A Flash Developer Resource Site

Results 1 to 18 of 18

Thread: [RESOLVED] loadSound streaming/setVolume problem.

  1. #1
    http://www.isamphibian.com
    Join Date
    Apr 2006
    Location
    UK
    Posts
    15

    [RESOLVED] loadSound streaming/setVolume problem.

    hi
    new to this place hope someone can help.

    im trying to build a simple streaming player, no playlists or anything.

    the problem:
    i cant set the volume for my streaming music before it plays.
    the code is inside the 'Play' button

    mySound.loadSound(url,true)

    no matter what volume level i set on my volume knob, the stream starts playing at 100%.
    now i can sort of undersand why...because my

    mySound = new Sound(this);

    is placed in Frame1 of the stage.
    if i were to place

    mySound.loadSound(url,true)
    mySound.stop() //so that it doesnt start playing when the movie loads

    in Frame1 of the stage as well, the volume settings work perfectly.
    though, the dilemma is...i dont want the player to start streaming the huge mp3 as soon as the movie loads.

    please please help.

  2. #2
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,490
    Try this in frame 1;

    mySound = new Sound(this);
    this.onLoad = function(){
    mySound.setVolume(0);
    }

    If the code to load sound is inside the play button, then your path is wrong. You have to use _root.mySound inside the button.
    Last edited by Ask The Geezer; 04-09-2006 at 03:55 PM.

  3. #3
    http://www.isamphibian.com
    Join Date
    Apr 2006
    Location
    UK
    Posts
    15
    thanks for the reply.
    but unfortunately that didnt make a difference.
    in fact putting
    mySound.setVolume(75);
    within the onLoad function meant that my volume knob didnt update when i loaded movie. (at setVolume(75) my volume knob would point to about 1 o'clock)

    hmm
    i think the problem lies in having

    mySound.loadSound("url", true);

    in my Play button. i dont think any other codes within the player recognises the existence of 'mySound'.
    as soon as that line loads, any volume setting via my volume knob or even
    mySound.setVolume(75);
    is 'forgotten'.

    i was thinking of loading the stream with on(press) on my play button
    and then having a volume code that would getVolume and then setVolume for a 'second' time.
    ive didnt have much sucess because of my limited actionscript knowledge.
    even though this method wouldnt have the best working player in the world...its the only possibility i can think of so far.

    im guessing there is just no way to put loadSound in frame 1 WITHOUT the player streaming immediately upon loading?
    on my other player, because it plays the background music, im allowed to have the loadSound in frame 1.
    and my Play button only has something like

    on(release){
    _root.mySound.start(0,0);
    }

    and all volume settings would work perfectly.

    heres the code in my volume knob just in case. obviously im not yet capable of writing all that myself.
    it was actually off a volume knob tutorial.
    thanks.

    onClipEvent(load){
    maxRotAngle = 120;
    //read the initial volume & set the position of the knob this.rotbutton.
    this.rotbutton._rotation = (2*_root.s.getVolume() - 100)*maxRotAngle/100;
    }

    /*
    set the volume depending on the position of the knob
    use formula to convert _rotation into volume range
    */
    onClipEvent(enterFrame){
    if (rotbutton.dorotate) {
    _root.s.setVolume(Math.floor((100+this.rotbutton._ rotation/maxRotAngle*100)/2));
    }
    }

  4. #4
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,490
    Your using 2 different sound objects. mySound on frame 1 and 's' in the volume control. And just adding the mysound object in frame 1 does not make it play. It doesn't play the sound till you load it. But why put it on root at all? Put everything inside a movie clip and oput the clip on the main timeline.

    You can also download all kinds of player fla files to see how it's done, from the 'Movies" link at the top of the page.

    We also have a Sound forum here at FK.

  5. #5
    http://www.isamphibian.com
    Join Date
    Apr 2006
    Location
    UK
    Posts
    15
    thanks again.

    er yer sorry
    i was only posting 'mySound' for simplicity's sake.
    all my objects are actually called 's'
    so s.loadSound s.setVolume etcetc
    just forgot to change the bit in my volume control before posting.

    the reason i didnt want to put
    mySound.loadSound(url, true)
    in the root is because it starts streaming as soon as the swf is loaded up on a webpage.
    certainly that seems to be the proper way to do it because it defines for the whole player what 'mySound' actually is.
    i can stop the music playing when the swf loads.
    i just add mySound.stop() to stop it playing.
    problem is, it seems to continue streaming the huge music file taking up all the bandwidth necessary to load the rest of the page.
    thats why i didnt want to put it in root.

    i have thought about putting it inside a MC but couldnt work out how to do it....
    i know how to import mp3s and stuff into the library and attach it to symbols
    but not a streaming mp3 off a website.
    certainly i dont want to import the whole song into my swf because that would seriously bloat everything defeating the point in streaming the song lol

    ive searched up and down and it seems no other player is coded the way i am doing it.

    yes i noticed theres a sound section
    but im a newbie as well lol

  6. #6
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    Hi yellowchilli, what exactly are you wanting to do. Maybe i can help you.
    If you don't think you're going to like the answer, then don't ask the question.

  7. #7
    http://www.isamphibian.com
    Join Date
    Apr 2006
    Location
    UK
    Posts
    15
    hi eqflash

    im trying to make a streaming mp3 player that is all.
    using loadSound to stream an external mp3 file.

    the thing is i cannot put loadSound in root because i dont want it to start streaming soon as the swf loads.
    but then if i dont put it in root, and putting it straight into my Play button instead,
    then it seems that the sound object doesnt define properly leading to flash 'forgetting' my volume settings: whether on the volume knob, or mySound.setVolume(75) in root.

    does that make sense?

    if you load
    http://www.angelfire.com/clone2/yell...angaplayer.swf
    set the volume first with the volume knob, then press Play you'll see what i mean by 'forgetting' the volume setting.

    thanks

  8. #8
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    you can stream the sound from the root timeline using loadSound, just put a stop() after the loadSound, i.e.

    PHP Code:
    = new Sound();
    s.loadSound("url"true);
    s.stop(); 
    do you have anything that is setting the volume in your button code?
    Last edited by EQFlash; 04-09-2006 at 08:34 PM.
    If you don't think you're going to like the answer, then don't ask the question.

  9. #9
    http://www.isamphibian.com
    Join Date
    Apr 2006
    Location
    UK
    Posts
    15
    well i dont exactly want to do that.
    but that method so far is the only way the volume settings work.
    the file i have to stream is huge so i dont want it do start streaming at all unless the user clicks Play.

    i use a rotating volume knob to control the volume.
    the whole code is about 3 posts up.

    and my sound object is actually 's'.
    not 'mySound'.
    i just thought that would be easier to read.

    thanks

  10. #10
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    what version of flash are you using? i'll send you a sample.
    If you don't think you're going to like the answer, then don't ask the question.

  11. #11
    http://www.isamphibian.com
    Join Date
    Apr 2006
    Location
    UK
    Posts
    15
    Flash Pro 8.

  12. #12
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    see attached. check out the code on the volume knob. let me know if this helps.
    Last edited by EQFlash; 03-04-2008 at 12:43 AM.
    If you don't think you're going to like the answer, then don't ask the question.

  13. #13
    http://www.isamphibian.com
    Join Date
    Apr 2006
    Location
    UK
    Posts
    15
    thanks

    i have exactly the same bit of volume control code actually...
    just except the volume readout.

    attached is what i have at the moment.
    sorry the codes are kind of everywhere...

    if you try swapping the s.loadSound line from Play button to root, with a stop()
    the volume settings will work perfectly
    even though the song doesnt play because of the stop()
    it will STILL start streaming.
    you will see this if you have a bandwidth meter or something.
    Attached Files Attached Files

  14. #14
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    streaming the sound allows the user to play the sound as it downloads, otherwise the user has to wait until the entire sound downloads before it can be played. It's better if it streams. You can also do this on the timeline.

    PHP Code:
    =  new Sound();
    s.stop(); 
    and on the play button
    PHP Code:
    on(release){
       
    _root.s.loadSound("url",true);

    though i don't recommend it.
    Last edited by EQFlash; 04-09-2006 at 09:23 PM.
    If you don't think you're going to like the answer, then don't ask the question.

  15. #15
    http://www.isamphibian.com
    Join Date
    Apr 2006
    Location
    UK
    Posts
    15
    yesyes and that is exactly what im trying to do.
    to stream a huge external mp3 file.
    just that...i really dont want it to start downloading until user clicks Play.

  16. #16
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    here's the same type sample only with the sound downloading on click of the button. You can still set the volume knob before playing the sound.
    Last edited by EQFlash; 03-04-2008 at 12:43 AM.
    If you don't think you're going to like the answer, then don't ask the question.

  17. #17
    http://www.isamphibian.com
    Join Date
    Apr 2006
    Location
    UK
    Posts
    15
    great that seems to work perfectly.
    id have to lookin into it in detail tomorrow though at its already 3am.

    thanks very much.

  18. #18
    http://www.isamphibian.com
    Join Date
    Apr 2006
    Location
    UK
    Posts
    15
    eqflash

    my player seems to work perfectly too now.
    hoever ive been trying to understand what 'sovolume' is.
    from what i see...
    'sovolume' is the variable for that textbox
    the volume knob updates box with a volume output level
    and then when the play button is pressed, flash takes that readout and applies it to the sound object 's'
    is that right?

    at one point i did try and work out something like
    s.setVolume=s.getVolume
    in my Play button but i gave up not knowing enough actionscript.
    but i never thought using a text box between them would work.

    anyway thank you very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center