• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

A Problem with online stream player

Guest
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

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

TOPICS
ActionScript

Views

6.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 23, 2012 Mar 23, 2012

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

...

Votes

Translate

Translate
Advocate ,
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

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??

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

here:

pre stop position: 2229.115646258503

post stop position: 2229.115646258503

play position: 2229.115646258503

but i guess it worked now :S

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

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

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

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


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

compilor error:

Scene 1, Layer 'Layer 2', Frame 3, Line 691136: Incorrect number of arguments.  Expected 1.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

what's on line 69 of frame 3?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

sorry think i just spotted it

replace

snd = Sound();

with

snd = new Sound();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

so anyone else can help me instead??

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 21, 2012 Mar 21, 2012

Copy link to clipboard

Copied

Bump...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 21, 2012 Mar 21, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 22, 2012 Mar 22, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2012 Mar 22, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines