A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Sound Player Problems

  1. #1
    Magister Psyberium's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    149

    Sound Player Problems

    Is there a way to make an MP3 load automatically when a specific frame is reached? Also for some reason I can't get my Pause button to work when I use loadSound instead of attachSound. Thanx.

  2. #2
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    yes, just place the sound object loadSound() method in the frame where you want the mp3 to load.

    you will have to post the pause button code for us to help you. Please only post only the relevant code not the complete code for your player.

  3. #3
    Magister Psyberium's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    149
    Thanks for your reply. I got the loadSound on the frame to work. But the problem I'm running into is with the second song on my player which is on a second frame. Both songs start loading even if the user has only entered the first frame. They share the same preloader. Here's part of the code for the second frame of the sound player. Is it a problem with the preloader? When somebody hits Next it takes them to the next frame where the song should load upon being entered.
    Stripsody = new Sound(StripsodyMC);
    StripsodyVolume = 100;
    Stripsody.loadSound("Stripsody.mp3");
    Stripsody.setVolume(StripsodyVolume);
    StripsodyPosition = _root.jukebox_mc.Stripsody.position/1000;
    this.onLoad = function() {
    StripsodyLoading = 0;
    _root.jukebox_mc.loadBar._xscale = StripsodyLoading;
    };
    // END onLoad
    this.onEnterFrame = function() {
    StripsodyBytesTotal = _root.jukebox_mc.Stripsody.getBytesTotal();
    StripsodyBytesLoaded = _root.jukebox_mc.Stripsody.getBytesLoaded();
    if (preloadNow == 1 && StripsodyBytesLoaded>0) {
    StripsodyLoading = Math.round((StripsodyBytesLoaded/StripsodyBytesTotal)*100);
    _root.jukebox_mc.percentLoadedText = StripsodyLoading+"%";
    _root.jukebox_mc.loadBar._xscale = StripsodyLoading;
    if (StripsodyLoading == 100) {
    preloadNow = 0;
    _root.Stripsody.start();
    }
    }
    };
    For my other problem with the pause button. I think for some reason its not keeping track of the song position. Here's the code:
    on (press) {
    StripsodyPosition = _root.jukebox_mc.Stripsody.position/1000;
    _root.jukebox_mc.Stripsody.stop();
    }
    Thanks.

  4. #4
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    if you have loadSound() in two different frames, but only want sound to load when a user enters the frame, then you need to place stop Actions in your timeline to control movement of the playhead.

    I dont see anything about this code that would cause loading of any other mp3 than "Stripsody.mp3".

    For the pause feature, the issue is with restarting playback at correct position, not stopping. Flash stops the sound where ever you tell it too. But you have to explicitly tell it to start at a position.

    // pause
    on (press) {
    StripsodyPosition = _root.jukebox_mc.Stripsody.position/1000;
    _root.jukebox_mc.Stripsody.stop();
    }

    // play
    on (press) {
    StripsodyPosition = _root.jukebox_mc.Stripsody.position/1000;
    _root.jukebox_mc.Stripsody.start(StripsodyPosition );
    }

    also you should use an if/then statement to reset position to 0 if the position is within 100ms of the end of the sound. Otherwise Flash will just play the last bit of the sound which is most likely inaudible and stop. It does not automatically reset the position to 0 after reaching the end of the sound.

  5. #5
    Magister Psyberium's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    149
    Thanks hp3 for your help. I did end up getting the pause button to work. It was missing an if (playing != true) play = true statement. Also i got the sounds to load separately on each frame.

    But the problem I still can't figure out is that when I test my movie, as soon as the sound loads immediately, then the music starts. But when I upload it to my site, the sound loads (eventhough it slows down my animation) but after it loads it doesn't play. But after I hit Stop, which resets the play=false variable and then I hit Play - the music plays!!! I don't get it. Can you see if I made any mistakes in my code. This is the code for the first frame, I took out stop and the volume variables.

    Summertime = new Sound(SummertimeMC);
    Summertime.loadSound("Summertime.mp3");
    preloadNow = 1;
    SummertimePosition = _root.jukebox_mc.Summertime.position/1000;
    this.onLoad = function() {
    SummertimeLoading = 0;
    _root.jukebox_mc.loadBar._xscale = SummertimeLoading;
    };
    this.onEnterFrame = function() {
    SummertimeBytesTotal = _root.jukebox_mc.Summertime.getBytesTotal();
    SummertimeBytesLoaded = _root.jukebox_mc.Summertime.getBytesLoaded();
    if (preloadNow == 1 && SummertimeBytesLoaded>0) {
    SummertimeLoading = Math.round((SummertimeBytesLoaded/SummertimeBytesTotal)*100);
    _root.jukebox_mc.percentLoadedText = SummertimeLoading+"%";
    _root.jukebox_mc.loadBar._xscale = SummertimeLoading;
    _root.jukebox_mc.box.list = "Summertime";
    if (SummertimeLoading == 100) {
    playing = true;
    _root.jukebox_mc.Summertime.start(SummertimePositi on, 0);
    preloadNow = 0;
    _root.jukebox_mc.box.list = "Summertime";
    }
    }
    };
    Thanks for your time.

  6. #6
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    I dont have an answer for you. In these situations you need to simply your code and break it down into smaller pieces to analyze the problem. good luck.

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