1 2 Previous Next 59 Replies Latest reply: Mar 30, 2012 6:37 AM by kglad RSS

    A Problem with online stream player

    maxwel11

      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

        • 1. Re: A Problem with online stream player
          _spoboyle Community Member

          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;
                    }
          }
          
          • 2. Re: A Problem with online stream player
            maxwel11 Community Member

            used it but non changed same problem. maybe need to clear a cache or sumthing or maybe i need to add sumthing to the stopSound function??

            • 3. Re: A Problem with online stream player
              _spoboyle Community Member

              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)

              • 4. Re: A Problem with online stream player
                maxwel11 Community Member

                here:

                 

                pre stop position: 2229.115646258503

                post stop position: 2229.115646258503

                play position: 2229.115646258503

                 

                but i guess it worked now :S

                • 5. Re: A Problem with online stream player
                  maxwel11 Community Member

                  but it doesn't differ now as its playing from the last part that i stopped the player at but i want it to play as if its connecting to the stream from the begining not at position i [ressed the stop button at (not as pause button) :S

                   

                   

                  thanks in advance

                  • 6. Re: A Problem with online stream player
                    _spoboyle Community Member

                    sorry i don't understand. you want it to play from the beginning?

                     

                    then use the code you had before snd.play()

                    • 7. Re: A Problem with online stream player
                      maxwel11 Community Member

                      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

                      • 8. Re: A Problem with online stream player
                        _spoboyle Community Member

                        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

                        • 9. Re: A Problem with online stream player
                          maxwel11 Community Member

                          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

                          • 10. Re: A Problem with online stream player
                            _spoboyle Community Member

                            right ok this is because you can't reload a Sound sorry I didn't look into that before

                             

                            try something like

                             

                            function playSound(event:MouseEvent):void {
                             
                                      if (isPlaying == false) {
                             
                                           
                                           snd = Sound();
                                           snd.load(songURL, context);
                                           channel = snd.play();
                                           isPlaying = true;
                                      }
                            }
                            
                            
                            
                            
                            • 11. Re: A Problem with online stream player
                              maxwel11 Community Member

                              compilor error:

                               

                              Scene 1, Layer 'Layer 2', Frame 3, Line 691136: Incorrect number of arguments.  Expected 1.
                              • 12. Re: A Problem with online stream player
                                _spoboyle Community Member

                                what's on line 69 of frame 3?

                                • 13. Re: A Problem with online stream player
                                  _spoboyle Community Member

                                  sorry think i just spotted it

                                   

                                  replace

                                   

                                  snd = Sound();

                                   

                                  with

                                   

                                  snd = new Sound();

                                  • 14. Re: A Problem with online stream player
                                    maxwel11 Community Member

                                    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

                                    • 15. Re: A Problem with online stream player
                                      _spoboyle Community Member

                                      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

                                      • 16. Re: A Problem with online stream player
                                        maxwel11 Community Member

                                        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

                                        • 17. Re: A Problem with online stream player
                                          _spoboyle Community Member

                                          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

                                          • 18. Re: A Problem with online stream player
                                            _spoboyle Community Member

                                            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

                                            • 19. Re: A Problem with online stream player
                                              maxwel11 Community Member

                                              yea i forgot to write false instead of true :X ik there is no securitypolicy but ts not the main problem and i thought about that way of hacking but u know the player will keep loading the stream and gonna be only a problem for users

                                              • 20. Re: A Problem with online stream player
                                                maxwel11 Community Member

                                                i wish i could know too why we can't recieve an open event :SS idk i used as2 more than as3 but really it had less probs

                                                • 21. Re: A Problem with online stream player
                                                  maxwel11 Community Member

                                                  so anyone else can help me instead??

                                                  • 22. Re: A Problem with online stream player
                                                    maxwel11 Community Member

                                                    Bump...

                                                    • 23. Re: A Problem with online stream player
                                                      kglad MVP

                                                      there are too many messages to follow this thread.  summarize in one message the current state of your issue just as if it were your first post.

                                                      • 24. Re: A Problem with online stream player
                                                        maxwel11 Community Member

                                                        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.

                                                        • 25. Re: A Problem with online stream player
                                                          kglad MVP

                                                          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.

                                                          • 26. Re: A Problem with online stream player
                                                            maxwel11 Community Member

                                                            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);


                                                            • 27. Re: A Problem with online stream player
                                                              _spoboyle Community Member

                                                              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

                                                              • 28. Re: A Problem with online stream player
                                                                maxwel11 Community Member

                                                                idk, i feel there is no solution although there are many projects out there of flash streaming players :S

                                                                • 29. Re: A Problem with online stream player
                                                                  kglad MVP

                                                                  it worked for me numerous times but i didn't use a "streaming" server, are you?

                                                                   

                                                                  what's the mp3's url?  what's the url of your test html?

                                                                  • 30. Re: A Problem with online stream player
                                                                    kglad MVP

                                                                    oh, i see the sounds url.

                                                                     

                                                                    that's the sound's server issue.  it's not allowing repeated downloads of its sound.  they probably don't want users screwing around with their bandwidth.

                                                                    • 31. Re: A Problem with online stream player
                                                                      maxwel11 Community Member

                                                                      so thats from the server itself? means if i used another it will work?

                                                                      • 32. Re: A Problem with online stream player
                                                                        maxwel11 Community Member

                                                                        actually i used several other links and it got same issue so it's not server problem but its sumthing wrong with flash itself :S

                                                                         

                                                                        even tried an icecast server too but same...

                                                                        • 34. Re: A Problem with online stream player
                                                                          maxwel11 Community Member

                                                                          no all good it play everytime i stop and play it bak nothing wrong actually with it

                                                                           

                                                                          but maybe cuz it's not a stream from server like mine??

                                                                          • 35. Re: A Problem with online stream player
                                                                            kglad MVP

                                                                            exactly.  that's what i said.  it's a server streaming issue.

                                                                             

                                                                            at least, that's what it looked like to me before because someone had posted security context error 2000.

                                                                            • 36. Re: A Problem with online stream player
                                                                              maxwel11 Community Member

                                                                              so no any way of making that work? and if thats it then how those flash streaming plauers out there work? and how normal players like windows media player and real player can stop the stream and replay it anytime and as often as u like ??

                                                                              • 37. Re: A Problem with online stream player
                                                                                kglad MVP

                                                                                you can make some things work:  http://www.kglad.com/Files/forums/streamError2.html

                                                                                 

                                                                                (left button starts, right stops)

                                                                                • 38. Re: A Problem with online stream player
                                                                                  maxwel11 Community Member

                                                                                  this is stream?? i guess it is . how u make it work??? xD give me the solution kglad please

                                                                                  • 39. Re: A Problem with online stream player
                                                                                    kglad MVP

                                                                                    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);

                                                                                    }

                                                                                    1 2 Previous Next