actually i got whole player working well but all my problem is when the stream is loaded at first time when swf is loaded by browser the stream begins to play and everything is fine with that but main problem is that when i press the stop button then play button again the stream don begin from current stream time (like it don play from now stream point) but it plays from the begining from the time the swf file was loaded very begining (when swf was loaded and stream was autoplayed) and this is my main problem tried experiencing with problem for lonnng time but no use. any idea?
here main part of code:
var snd:Sound = new Sound();
var volnum:Number = 1;
var context:SoundLoaderContext = new SoundLoaderContext(8000, true);
snd.load(songURL, context);
var channel:SoundChannel;
channel = snd.play();
isPlaying = true;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
var bytes:ByteArray = new ByteArray();
function playSound(event:MouseEvent):void {
if (isPlaying == false) {
channel = snd.play();
isPlaying = true;
} else {
}
}
function stopSound(event:MouseEvent):void {
channel.stop();
isPlaying = false;
}
playBtn.addEventListener(MouseEvent.CLICK, playSound);
stopBtn.addEventListener(MouseEvent.CLICK, stopSound);
volDownBtn.addEventListener(MouseEvent.CLICK, volumeDown);
volUpBtn.addEventListener(MouseEvent.CLICK, volumeUp);
wish anyone can help with that problem that took me while without finding a solution
thanks alot
snd.play() will always start the playback from the beginning
public function play(startTime:Number = 0, ...):SoundChannel
to resume where it was stopped use this
function playSound(event:MouseEvent):void {
if (isPlaying == false) {
channel = snd.play(channel.position);
isPlaying = true;
}
}
well if you are viewing this in a browser you would need to clear the browsers cache in order to see the new swf. however you can try 2 things.
function stopSound(event:MouseEvent):void {
trace("pre stop position: " + channel.position);
channel.stop();
trace("post stop position: " + channel.position);
isPlaying = false;
}
and
function playSound(event:MouseEvent):void {
if (isPlaying == false) {
trace("play position: " + channel.position);
channel = snd.play(channel.position);
isPlaying = true;
}
}
and let me know the output from the 3 trace statements
if you are running this in a browser, you will need to find the flashlog.txt file on your machine
(e.g. C:\Users\{username}\AppData\Roaming\Macromedia\Flash Player\Logs)
sorry for not being that clear. imma try to tell u everything in points
at first before ur code when i used to load the swf file it used to play the stream but when i press the stop button then back the play it used to playing from the begining of the online stream (since the swf was loaded at first)
now when i use ur code when i press the stop button then back the play one it plays from the last part i stopped the stream at. (which is the second best choice for me but not the best)
what i need is that when i stop the stream by pressing the stop button then i press the play again the player load the stream from the begining as if it didn't before to play from current time of what is broadcasting from shoutcast server at the moment not at position i pressed stop or from position when the player/swf file was loaded. ( like any other regular player playing online stream like windows media player/ real player etc...) and thats what i need exactly
thanks in advance
ok, if i understand you correctly that means you will have reload the sound when you click play.
function playSound(event:MouseEvent):void {
if (isPlaying == false) {
snd.load(songURL, context);
channel = snd.play();
isPlaying = true;
}
}
function stopSound(event:MouseEvent):void {
channel.stop();
isPlaying = false;
}
this will stop the stream when stopSound is called
and then when you call playSound the snd object will get the latest stream from the server and start playing again
i tried that before and it didn't work but i still tried it now too and that is the output error i get now and used to get when i tried what u gave:
Error: Error #2037: Functions called in incorrect sequence, or earlier call was unsuccessful.
at flash.media::Sound/_load()
at flash.media::Sound/load()
at what_fla::MainTimeline/playSound()
this output error appear when i press the play button after stopping it. also, the stream don play back.
Thanks in advance
plays well and when i press stop then play at first it work well but when i do same progress again it stop the stream when press stop but don play anymore when the play button is pressed and and out put error appears which is:
SecurityError: Error #2000: No active security context.
and this error is repeated everytime i try to press play after stopping it for 2nd time
btw i tried that before also but ended up with same error but didn't know how to continue.
thanks alot
I have constrcuted a demo project to try and simulate your problem. I've got it working and indeed my example doesn't play anymore sound after you stop and play twice.
However I don't get the error you are seeing I just get no sound, and I do have a valid sound channel after calling play for the thrid time. this is very odd I've try and look into it but i'm running out of ideas
its ok bro i had this problem for loong time but donno never had a solution and i like left it for long time when i surrendered rofl. now thought i can get any help from others and maybe i missed sumthing others can complete
you tried hard to help
thanks in advance xD and ye its too odd :S
btw there is a hack you could use to get it working.
instead of stopping the sound playback with channel.stop()
you could just mute the channel until the user clicks play and then restore the previous volume.
It ain't pretty but if there is no other way it should work.
also you use
context = new SoundLoaderContext(8000, true);
and the url I have been connecting too has a invalid securityPolicy file and so unless you need specific function calls in flash it might be worth trying
(their crossdomain file seems invalid as well)
context = new SoundLoaderContext(8000, false);
but maybe you don't have the same problem as me
summorizing all of that:
is that i had problem that when i press the stop button of my streaming radio player then play button back it used to play from the position where the whole swf file was loaded and the stream got autoplayed which really bother me. cuz i want it when i stop then press the play again it begin reloading the stream again and then play from what is streaming through the server atm not when the swf was loaded. but then _spoboyle wrote me a code that when i press the stop button the position get traced then it plays back from that position which i don want to cuz i want the player to play the new stream not until stopped too (like most players out there media player/real) so he gave me a code which is that
function playSound(event:MouseEvent):void {
if (isPlaying == false) {
snd = new Sound();
snd.load(songURL, context);
channel = snd.play();
isPlaying = true;
}
}
function stopSound(event:MouseEvent):void {
channel.stop();
isPlaying = false;
}
which make the stream gets reloaded after i press the play button which exactly what i want and what i tried before by myself but the problem now that after you stop the stream then play it, it work well at first time but when u do it again it stops but never play again. and that what _spoboyle concluded after he constrcuted a demo project to try and simulate my problem:
I'll jsut add one more thing
on the second time of pressing "play" I am not receiving an OPEN event, which I believe is what's causing the issue
but I cannot tell why I am not receiving the OPEN event
thats mainly everything in brief
thanks in advance for everyone who trying to help and especially kglad which helped me in a previous as2 problem.
you don't have an open event listener in playSound so that's why you're not seing an open event. use:
function playSound(event:MouseEvent):void {
if (isPlaying == false) {
if(snd){
snd.removeEventListener(Event.OPEN,f);
}
snd = new Sound();
snd.addEventListener(Event.OPEN,f);
snd.load(songURL, context);
channel=snd.play();
isPlaying=true;
}
}
function f(e:Event):void{
trace(e);
}
and i don't see any problem repeatedly playing/stopping a sound using your code.
still don't work after 2nd time of pressing play button and here is the trace output:
[Event type="open" bubbles=false cancelable=false eventPhase=2]
Error opening URL 'http://radio.virtualdj.com:8000/;stream.nsv'
SecurityError: Error #2000: No active security context.
//http://radio.virtualdj.com:8000/;stream.nsv' << is the link of the stream.
here is main part of the code:
function playSound(event:MouseEvent):void {
if (isPlaying == false) {
if(snd){
snd.removeEventListener(Event.OPEN,f);
}
snd = new Sound();
snd.addEventListener(Event.OPEN,f);
snd.load(songURL, context);
channel=snd.play();
isPlaying=true;
}
}
function f(e:Event):void{
trace(e);
}
function stopSound(event:MouseEvent):void {
channel.stop();
isPlaying = false;
}
playBtn.addEventListener(MouseEvent.CLICK, playSound);
stopBtn.addEventListener(MouseEvent.CLICK, stopSound);
volDownBtn.addEventListener(MouseEvent.CLICK, volumeDown);
volUpBtn.addEventListener(MouseEvent.CLICK, volumeUp);
hey kglad
kglad wrote:
you don't have an open event listener in playSound so that's why you're not seing an open event. use:
function playSound(event:MouseEvent):void {
if (isPlaying == false) {
if(snd){
snd.removeEventListener(Event.OPEN,f);
}
snd = new Sound();
snd.addEventListener(Event.OPEN,f);
snd.load(songURL, context);
channel=snd.play();
isPlaying=true;
}
}
function f(e:Event):void{
trace(e);
}
and i don't see any problem repeatedly playing/stopping a sound using your code.
nor did I until I actually tried it
in the project I set up I did have an OPEN event listener and noticed it wasn't being received after the 3rd time of playing the stream
I have a single class example if you want me to email it over or anything so you can see what's going on
do you/hear a problem here: http://www.kglad.com/Files/forums/Untitled-1.html
you can make some things work: http://www.kglad.com/Files/forums/streamError2.html
(left button starts, right stops)
yes, that's using your streaming url.
if that is working the way you want, the key is closing the stream (if it's still open - using the sound class'es close() method) before trying to open another stream. that server does not like multiple streams open at one time.
here's the code:
//////////////////////////////////////////////////////////////////////
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.events.IOErrorEvent;
import flash.events.Event;
var snd:Sound;
var channel:SoundChannel;
var isPlaying:Boolean;
var isStreaming:Boolean;
var songURL:URLRequest = new URLRequest('http://radio.virtualdj.com:8000/;stream.nsv');
var context:SoundLoaderContext = new SoundLoaderContext(8000, true);
b.addEventListener(MouseEvent.CLICK,playSound);
c.addEventListener(MouseEvent.CLICK,stopSound);
function playSound(event:MouseEvent):void {
if (isPlaying==false) {
if (snd) {
snd.removeEventListener(Event.OPEN,openF);
snd.removeEventListener(Event.COMPLETE,completeF);
snd.removeEventListener(IOErrorEvent.IO_ERROR,errorF);
}
snd = new Sound();
snd.addEventListener(Event.OPEN,openF);
snd.addEventListener(Event.COMPLETE,completeF);
snd.addEventListener(IOErrorEvent.IO_ERROR,errorF);
snd.load(songURL, context);
channel=snd.play();
isPlaying=true;
}
}
function stopSound(event:MouseEvent):void {
channel.stop();
if(isStreaming){
snd.close()
}
isPlaying=false;
}
function completeF(e:Event):void{
isStreaming = false;
}
function openF(e:Event):void {
isStreaming = true;
}
function errorF(e:IOErrorEvent):void{
trace(e);
}
North America
Europe, Middle East and Africa
Asia Pacific