0

Here is my code, for my MP3 streaming player (mp3player.swf) in AS3

var stream:String               = root.loaderInfo.parameters.stream;
var sndObject:Sound             = new Sound();
var chaObject:SoundChannel      = new SoundChannel() ;

btnStop.addEventListener(MouseEvent.CLICK, stopPlayback);   
btnPlay.addEventListener(MouseEvent.CLICK, startPlayback);

btnStop.visible = false;

function startPlayback(e:MouseEvent):void {
    btnPlay.visible = false;
    btnStop.visible = true;
    //stream  = root.loaderInfo.parameters.stream;
    sndObject = new Sound(new URLRequest(stream));
    chaObject = sndObject.play(0);  
}

function stopPlayback(e:MouseEvent):void {
    chaObject.stop();       
    btnPlay.visible = true;
    btnStop.visible = false;
}

And here is my html file, that contains mp3player.swf

<!DOCTYPE html> 
<html lang="en"> 
    <head>
        MP3 Player
    </head>
    <body>
    <div id="areas">
                <h3>MP3 Player</h3>
                <div id="player">
                    <object id="f4Player" width="300" height="181" type="application/x-shockwave-flash" data="mp3player.swf"> 
                    <param name="movie" value="mp3player.swf" /> 
                    <param name="quality" value="high" /> 
                    <param name="menu" value="false" /> 
                    <param name="scale" value="noscale" /> 
                    <param name="allowfullscreen" value="true">
                    <param name="allowscriptaccess" value="always">
                    <param name="swlivevonnect" value="true" /> 
                    <param name="cachebusting" value="false">
                    <param name="flashvars" value="stream=http://123.30.174.216:8768/VOVGT"/> 
                    <a href="http://www.adobe.com/go/getflash"> 
                        <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player"/> 
                    </a> 
                    <a href="http://gokercebeci.com/dev/flvplayer" title="flv player">flv player</a> 
                    </object> 
                </div>                
            </div>
            <!-- /development area -->
        </div>
    </body>
</html> 

Problem is when I click the play button, it plays a sound, then I click stop, and click play again, however this time it doesn't play any sound.Can anyone help me? Thanks a lot, in advance!

1 Answer 1

1

Try init sound object outside startPlayback function otherwise, it will create new sound instance each time you click play

put

sndObject = new Sound(new URLRequest(stream));

before this line

function startPlayback(e:MouseEvent):void {

Sign up to request clarification or add additional context in comments.

1 Comment

thanks you, but if i do this, this music "can't stop" streaming. eg, i play radio streaming (live streaming), when i do this, stop function "not stop", it same the pause function. It mean when i click stop and play, it play from when i click stop. but i want it play new progress from live streaming. can you help me?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.