Mp3 loader with seek


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //***mp3 loader
  2. _root.createEmptyMovieClip("seek",1)
  3.  
  4. seek.w=140 // seek bar width
  5. seek.h=20 // seek bar height
  6. seek.b=2 // seek bar border
  7. seek.plc="0xff0000" // seek bar preload color
  8. seek.bgc="0x000000" // seek bar background color
  9. seek.fgc="0xffffff" // seek bar foreground color
  10.  
  11. plw=seek.w-2*seek.b
  12.  
  13. MovieClip.prototype.drawSquare=function(w,h,l,t,c) {
  14. with(this){
  15. clear()
  16. beginFill(c,100)
  17. moveTo(l,t)
  18. lineTo(l+w,t)
  19. lineTo(l+w,t+h)
  20. lineTo(l,t+h)
  21. lineTo(l,t)
  22. endFill()
  23. }
  24. return this
  25. }
  26.  
  27. seek.jump=function() {
  28. mp3.start((((seek.bg._xmouse-seek.b)/plw)*(mp3.duration/loaded))/1000)
  29. }
  30.  
  31. seek.createEmptyMovieClip("bg",1).drawSquare(seek.w,seek.h,0,0,seek.bgc)
  32. seek.createEmptyMovieClip("pl",2).drawSquare(1,seek.h-2*seek.b,0,seek.b,seek.plc)._x=seek.b
  33. seek.createEmptyMovieClip("fg",3).drawSquare(1,seek.h-2*seek.b,0,seek.b,seek.fgc)._x=seek.b
  34.  
  35. mp3=new Sound()
  36. mp3.loadSound("diggnation.mp3", true)
  37. mp3.start(0)
  38. seek.pl.onEnterFrame=function () {
  39. out=loaded=mp3.getBytesLoaded()/mp3.getBytesTotal()
  40. this._width=plw*loaded
  41. seek.fg._width=out2=(mp3.position/(mp3.duration/loaded))*plw
  42. }
  43. seek.pl.onPress=function () {
  44. seek.jump()
  45. this.onMouseMove=function () {
  46. if (this.hitTest(_root._xmouse,_root._ymouse,false)){seek.jump()}
  47. }
  48. }
  49. seek.pl.onRelease=seek.pl.onReleaseOutside=function () {
  50. delete this.onMouseMove
  51. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.