Skip navigation
Currently Being Moderated

A Problem with online stream player

Mar 19, 2012 3:10 AM

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

 
Replies 1 2 Previous Next
  • Currently Being Moderated
    Mar 19, 2012 3:38 AM   in reply to maxwel11

    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;
              }
    }
    
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 19, 2012 3:51 AM   in reply to maxwel11

    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)

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 19, 2012 4:17 AM   in reply to maxwel11

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

     

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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 19, 2012 4:35 AM   in reply to maxwel11

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 19, 2012 5:10 AM   in reply to maxwel11

    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;
              }
    }
     
     
     
    
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 19, 2012 5:26 AM   in reply to maxwel11

    what's on line 69 of frame 3?

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 19, 2012 5:27 AM   in reply to _spoboyle

    sorry think i just spotted it

     

    replace

     

    snd = Sound();

     

    with

     

    snd = new Sound();

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 19, 2012 6:28 AM   in reply to maxwel11

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 19, 2012 7:09 AM   in reply to maxwel11

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 19, 2012 7:11 AM   in reply to _spoboyle

    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

     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 21, 2012 2:03 PM   in reply to maxwel11

    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.

     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 22, 2012 7:38 AM   in reply to maxwel11

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 22, 2012 9:06 AM   in reply to kglad

    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

     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 22, 2012 10:09 AM   in reply to maxwel11

    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?

     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 22, 2012 10:10 AM   in reply to kglad

    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.

     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 22, 2012 1:26 PM   in reply to maxwel11
     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 22, 2012 1:31 PM   in reply to maxwel11

    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.

     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 22, 2012 5:55 PM   in reply to maxwel11

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

     

    (left button starts, right stops)

     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 23, 2012 8:36 AM   in reply to maxwel11

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

    }

     
    |
    Mark as:
1 2 Previous Next
Actions

More Like This

  • Retrieving data ...

Incoming Links

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points