A Flash Developer Resource Site

Results 1 to 18 of 18

Thread: Anyone know how to loop MP3

  1. #1
    Junior Member
    Join Date
    Jul 2008
    Posts
    1

    Anyone know how to loop MP3

    If anyone can point me in the right direction on how to loop mp3's i would really appreciate it. Is there any program that will allow me to do that?

    Thanks for the help.

    -Vj

  2. #2
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    PHP Code:
    = new Sound();
    s.loadSound("yourSound.mp3"true);
    s.onEnterFrame = function () {
        
    pos this.position/1000;
        
    dur this.duration/1000;
        if (
    pos>=dur) {
            
    this.start();
        }
    }; 
    or if you are controlling sound object with a button to play it;
    PHP Code:
    = new Sound ();
    s.loadSound ("yourSound.mp3");
    playing false;
    button.onRelease = function () {
        if (!
    playing) {
            
    s.start ();
            
    playing true;
        }
        
    onEnterFrame = function () {
            
    pos s.position 1000;
            
    dur s.duration 1000;
            if (
    pos >= dur) {
                
    s.start ();
            }
        };
    }; 
    Last edited by EQFlash; 07-19-2008 at 09:17 AM.
    If you don't think you're going to like the answer, then don't ask the question.

  3. #3
    Professional Flash Developer
    Join Date
    Aug 2007
    Location
    California
    Posts
    105

    Do you want to skip the silnece or just loop the file?

    If you are looking to skip the leader and follower silence that occurs when trying to loop a loaded in .mp3 file, I created a tutorial to do this a while back. (AS2)

    http://www.8bitrocket.com/newsdispla...?newspage=3153

    I don't know if EQFlash's code does this, but I know it is quite a sticky problem.

  4. #4
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    Quote Originally Posted by 8bitjeff
    If you are looking to skip the leader and follower silence that occurs when trying to loop a loaded in .mp3 file, I created a tutorial to do this a while back. (AS2)

    http://www.8bitrocket.com/newsdispla...?newspage=3153

    I don't know if EQFlash's code does this, but I know it is quite a sticky problem.
    No my code doesn't do that, and i would like to remove that silence from my mp3 files. thanx for the link.
    If you don't think you're going to like the answer, then don't ask the question.

  5. #5
    Junior Member
    Join Date
    Aug 2008
    Posts
    21

    a simplest way

    var _sound = new MYMP3MUSIC();
    _sound.play(0, int.MAX_VALUE);

  6. #6
    Junior Member
    Join Date
    Aug 2008
    Posts
    21
    simplest way:
    var _sound = new YOURMP3MUSIC();
    _sound.play(0, int.MAX_VALUE);

  7. #7
    Junior Member
    Join Date
    Dec 2007
    Posts
    28
    I have a question similar to this: I already have my song cut into a loop-able format (if you loop it in the audio editor / itunes it looks perfectly). However when I import it into flash it.. isn't perfect, it sort of jumps at the end of the song making the loop sound sloppy. I have no idea what to do. I heard there was a way you could trick flash via AS to get it to work.. but maybe that's for something else

    can anyone help me out?

  8. #8
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    Quote Originally Posted by Warbreeder
    I have a question similar to this: I already have my song cut into a loop-able format (if you loop it in the audio editor / itunes it looks perfectly). However when I import it into flash it.. isn't perfect, it sort of jumps at the end of the song making the loop sound sloppy. I have no idea what to do. I heard there was a way you could trick flash via AS to get it to work.. but maybe that's for something else

    can anyone help me out?
    check out the link in the post above ^
    If you don't think you're going to like the answer, then don't ask the question.

  9. #9
    Junior Member
    Join Date
    Dec 2007
    Posts
    28
    Well, i did, and ultimately found this code

    Code:
    var my_sound:Sound = new Sound();
    my_sound.attachSound("TheSong");
    var follower:Number=50;
    var leader:Number=26;
    var placeToStop:Number=my_sound.duration-follower;

    When I stuck this in the frame, and tested the movie, nothing happened (no errors either)

    And yes the identifier for the music loop is TheSong

    any suggestions?

  10. #10
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    i have never tested the link nor the method of making seamless loops. i would guess you have to get the position of the sound. let me ask you, is your sound a wav or mp3? cause this covers mp3. mp3 files leaves a slight degree of silence for id3 info, as explained above. maybe you could you my code above and where it says pos = s.position/1000, make it pos = (s.position)+26. i'll have to run tests on it to see exactly what the number is.
    Last edited by EQFlash; 08-05-2008 at 07:01 PM.
    If you don't think you're going to like the answer, then don't ask the question.

  11. #11
    Junior Member
    Join Date
    Dec 2007
    Posts
    28
    Yes my song is an mp3. When I stuck both your script and the script from the site that was linked (in another fla) into a single frame, and tested the movie, nothing happened, and when I say that I mean the song didn't even play

  12. #12
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    that's because my script is for an external mp3 file, not one imported into flash IDE
    If you don't think you're going to like the answer, then don't ask the question.

  13. #13
    Junior Member
    Join Date
    Dec 2007
    Posts
    28
    Yeah thats no good, I'd rather have it from within the swf. Ah well, I shall keep searching

  14. #14
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    if you have access to the sound as WAV file, then import as WAV and use Flash built-in mp3 encoder. The Flash player will seamlessly loop sounds compressed with its built-in mp3 encoder because it knows how much of its own "leader" to skip.

  15. #15
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    if you have access to the sound as WAV file, then import as WAV and use Flash built-in mp3 encoder. The Flash player will seamlessly loop sounds compressed with its built-in mp3 encoder because it knows how much of its own "leader" to skip.

  16. #16
    Junior Member
    Join Date
    Dec 2007
    Posts
    28
    yeah thats the only issue here... when I convert the song to a wav file, not only does the quality begin to suck, but for some reason it goes from 300 kbs to 3 mb or so

  17. #17
    Junior Member
    Join Date
    Dec 2007
    Posts
    28
    Ok, this is the code I'm using (it loads the song off my computer, don't have it uploaded yet)

    Code:
    var leader:Number = 50;    
    var follower:Number = 50; 
    var placeToStop:Number;
    
    var track:Sound = new Sound(song1);
    track.loadSound("Song1.mp3", false);  
    track.onLoad = function(){
        track.start(song1);
        placeToStop = track.duration - follower;
    }
    
    var intervalVal:Number = setInterval( runMe , 1 );
    function runMe():Void{
        if (track.position > placeToStop) {
            track.stop();
            track.start(leader/1000);
        }
    }
    Now I have one question, say i have the script on frame 10 (thus starting the song to play) and I would like it to stop at frame 100. Should I would rather not use the command to stop all sound (which is the only one I know regarding this sort of thing) Is there any script I can place within the code? Or something on frame 100 to stop it?

    Thanks

  18. #18
    Junior Member
    Join Date
    Dec 2007
    Posts
    28
    (sorry for triple post)

    Just want to say I did mess around with the script a lot (well the second 1/2 mostly). I've tried a few things and nothing has worked so far

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