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
.
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 . CLICK , musicPause ); function musicPause ( e : MouseEvent ): void { if ( musicPlaying ) { musicPosition = theChannel . position ; theChannel . stop (); musicPlaying = false ; getTimes . removeEventListener ( TimerEvent . TIMER , doMusicTimer ); getTimes . stop (); } } buttonPlay . addEventListener ( MouseEvent . CLICK , musicPlay ); function musicPlay ( e : MouseEvent ): void { if (! musicPlaying ) { theChannel = theMusic . play ( musicPosition ); musicPlaying = true ; getTimes = new Timer ( 100 ); getTimes . addEventListener ( TimerEvent . TIMER , doMusicTimer ); getTimes . start (); bar . addEventListener ( MouseEvent . CLICK , jumpMusic ); } } buttonStop . addEventListener ( MouseEvent . CLICK , musicStop ); function musicStop ( e : MouseEvent ): void { musicPlaying = false ; musicPosition = 0 ; bar . innerBar . scaleX = musicPosition ; times . text = '00:00' + '/' + String ( totalMinutes ) + ':' + String ( totalSeconds ); getTimes . removeEventListener ( TimerEvent . TIMER , doMusicTimer ); 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 ); } }
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
.
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.
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
Forum Rules
Click Here to Expand Forum to Full Width