Reputation: 3
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!
Upvotes: 0
Views: 9125
Reputation: 26
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 {
Upvotes: 1