dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Music Length

  1. #1
    Junior Member
    Join Date
    Jul 2015
    Posts
    5

    Music Length

    Hi
    I would like to have a slider that shows the duration of the music being played on a MP3 player and as it count downs the remaining time left As the image shows Can anybody point me to a tutorial or instructions on how 2 as I am fairly new to AS3 Many thanks Martin
    Attached Images Attached Images

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    Perhaps you can get something from this, put an mp3 in the same directory as the published swf and call it song.mp3

    Or code if you prefer but will need to graphic it out.
    PHP Code:
    import flash.utils.Timer;
    import flash.events.MouseEvent;
    import flash.events.Event;

    var 
    theMusic:Sound = new Sound();
    var 
    theChannel:SoundChannel = new SoundChannel();
    var 
    theVolume = new SoundTransform();

    var 
    musicPosition:Number 0;

    var 
    musicPlaying:Boolean false;

    var 
    getTimes:Timer;

    var 
    totalMinutes:Number;
    var 
    totalSeconds:Number;
    var 
    currentMinutes:Number;
    var 
    currentSeconds:Number;

    bar.innerBar.scaleX 0;

    times.text '00:00/00:00';

    theMusic.load(new URLRequest("song.mp3"));

    theVolume.volume 0.5;
    theChannel.soundTransform theVolume;

    buttonPause.addEventListener(MouseEvent.CLICKmusicPause);

    function 
    musicPause(e:MouseEvent):void
    {
        if (
    musicPlaying)
        {
            
    musicPosition theChannel.position;

            
    theChannel.stop();

            
    musicPlaying false;

            
    getTimes.removeEventListener(TimerEvent.TIMERdoMusicTimer);
            
    getTimes.stop();
        }
    }

    buttonPlay.addEventListener(MouseEvent.CLICKmusicPlay);

    function 
    musicPlay(e:MouseEvent):void
    {
        if (! 
    musicPlaying)
        {
            
    theChannel theMusic.play(musicPosition);

            
    musicPlaying true;

            
    getTimes = new Timer(100);
            
    getTimes.addEventListener(TimerEvent.TIMERdoMusicTimer);
            
    getTimes.start();

            
    bar.addEventListener(MouseEvent.CLICKjumpMusic);
        }
    }

    buttonStop.addEventListener(MouseEvent.CLICKmusicStop);

    function 
    musicStop(e:MouseEvent):void
    {
        
    musicPlaying false;
        
    musicPosition 0;

        
    bar.innerBar.scaleX musicPosition;

        
    times.text '00:00' '/' String(totalMinutes) + ':' String(totalSeconds);

        
    getTimes.removeEventListener(TimerEvent.TIMERdoMusicTimer);
        
    getTimes.stop();

        
    theChannel.stop();
    }

    function 
    doMusicTimer(e:TimerEvent):void
    {
        
    totalMinutes Math.floor(theMusic.length 1000 60);
        
    totalSeconds Math.floor(theMusic.length 1000) % 60;
        
    currentMinutes Math.floor(theChannel.position 1000 60);
        
    currentSeconds Math.floor(theChannel.position 1000) % 60;

        
    bar.innerBar.scaleX theChannel.position theMusic.length;

        
    times.text numberFill(currentMinutes) + ':' numberFill(currentSeconds) + '/' numberFill(totalMinutes) + ':' numberFill(totalSeconds);
    }

    function 
    jumpMusic(e:MouseEvent):void
    {
        var 
    cue:Number theMusic.length * (bar.mouseX bar.width);

        
    theChannel.stop();
        
    theChannel theMusic.play(cue);

        
    musicPosition cue;
    }

    function 
    numberFill(arg:Number):String
    {
        if (
    arg 10)
        {
            return 
    '0' String(arg);
        }
        else
        {
            return 
    String(arg);
        }


  3. #3
    Junior Member
    Join Date
    Jul 2015
    Posts
    5
    Hello fruitbeard
    Wow this is fantastic a music player and timer all in one Thank you so much for your help I never dreamed it would be answered so quick Your a gent Many Thanks Martin

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    Here it is again with a few things ironed out, same again, song.mp3 same directory as swf.

    That should give you a good basis to start.

  5. #5
    Junior Member
    Join Date
    Jul 2015
    Posts
    5
    Hi fruitbeard
    That works fantastic and you have certainly put me on the road to learning new things I really appreciate your kind help thank you so much Regards Martin

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