WEB开发网
开发学院图形图像Flash 用纯AS写的简单MP3播放器(源代码) 阅读

用纯AS写的简单MP3播放器(源代码)

 2012-02-06 12:08:53 来源:本站整理   
核心提示:这是一段用as写的mp3播放器代码,把下面的代码复制到第一帧即可:fscommand("fullscreen", false); fscommand("allowscale", false); fscommand("showmenu", false);

这是一段用as写的mp3播放器代码,把下面的代码复制到第一帧即可:

  1. fscommand("fullscreen", false);   
  2. fscommand("allowscale", false);   
  3. fscommand("showmenu", false);   
  4. //加载外部声音   
  5. my_sound = new Sound();   
  6. my_sound.loadSound("http://bbs.wybstv.com.cn/v/春暖花开.mp3", true);   
  7. my_sound.start();   
  8. //循环播放   
  9. my_sound.onSoundComplete = function() {   
  10. my_sound.start();   
  11. };   
  12. //创建音量底线   
  13. this.createEmptyMovieClip("xing_mc", 1);   
  14. with (xing_mc) {   
  15. beginFill(0x009900);   
  16. moveTo(46, 11);   
  17. lineTo(100, 11);   
  18. lineTo(100, 12);   
  19. lineTo(46, 12);   
  20. lineTo(46, 11);   
  21. endFill();   
  22. }   
  23. //创建背景方框   
  24. this.createEmptyMovieClip("fangkang_mc", 2);   
  25. with (fangkang_mc) {   
  26. lineStyle(1, 0x008800);   
  27. moveTo(0, 0);   
  28. lineTo(260, 0);   
  29. lineTo(260, 14);   
  30. lineTo(0, 14);   
  31. lineTo(0, 0);   
  32. }   
  33. //创建音量滑块并控制音量   
  34. this.createEmptyMovieClip("drag_mc", 3);   
  35. with (drag_mc) {   
  36. beginFill(0x008800);   
  37. moveTo(46, 3);   
  38. lineTo(50, 3);   
  39. lineTo(50, 12);   
  40. lineTo(46, 12);   
  41. lineTo(46, 3);   
  42. endFill();   
  43. }   
  44. left = drag_mc._x;   
  45. right = left+50;   
  46. top = drag_mc._y;   
  47. bottom = drag_mc._y;   
  48. drag_mc._x = my_sound.getVolume();   
  49. drag_mc._x = 50;   
  50. drag_mc.onPress = function() {   
  51. this.startDrag(false, left, top, right, bottom);   
  52. };   
  53. drag_mcdrag_mc.onRelease = drag_mc.onReleaseOutside=function () {   
  54. stopDrag();   
  55. my_sound.setVolume((this._x)*2);   
  56. };   
  57. //按钮的可见性   
  58. pause_mc._visible = 1;   
  59. play_mc._visible = 0;   
  60. //创建播放按钮   
  61. this.createEmptyMovieClip("play_mc", 4);   
  62. with (play_mc) {   
  63. beginFill(0x008800);   
  64. moveTo(5, 3);   
  65. lineTo(14, 7.5);   
  66. lineTo(5, 12);   
  67. lineTo(5, 3);   
  68. endFill();   
  69. }   
  70. play_mc.onRelease = function() {   
  71. my_sound.start(time);   
  72. this._visible = 0;   
  73. pause_mc._visible = 1;   
  74. };   
  75. //创建停止按钮   
  76. this.createEmptyMovieClip("stop_mc", 5);   
  77. with (stop_mc) {   
  78. beginFill(0x008800);   
  79. moveTo(25, 3);   
  80. lineTo(34, 3);   
  81. lineTo(34, 12);   
  82. lineTo(25, 12);   
  83. lineTo(25, 3);   
  84. endFill();   
  85. }   
  86. stop_mc.onRelease = function() {   
  87. my_sound.stop();   
  88. pause_mc._visible = 0;   
  89. play_mc._visible = 1;   
  90. time=0   
  91. };   
  92. //创建暂停按钮   
  93. this.createEmptyMovieClip("pause_mc", 6);   
  94. with (pause_mc) {   
  95. beginFill(0x008800);   
  96. moveTo(5, 3);   
  97. lineTo(14, 3);   
  98. lineTo(14, 12);   
  99. lineTo(5, 12);   
  100. lineTo(5, 3);   
  101. endFill();   
  102. beginFill(0xFFFFFF);   
  103. moveTo(8, 3);   
  104. lineTo(11, 3);   
  105. lineTo(11, 12);   
  106. lineTo(8, 12);   
  107. lineTo(8, 3);   
  108. endFill();   
  109. }   
  110. pause_mc.onRelease = function() {   
  111. this._visible = 0;   
  112. play_mc._visible = 1;   
  113. my_sound.stop();   
  114. time = my_sound.position/1000;   
  115. };   
  116. //创建进度显示文本   
  117. this.createTextField("shijian_txt", 7, 112, -2, 100, 20);   
  118. shijian_txt.textColor = 0x009900;   
  119. shijian_txt.autoSize = true;   
  120. onEnterFrame = function () {   
  121. var totalseconds:Number = my_sound.duration/1000;   
  122. var minutes:Number = Math.floor(totalseconds/60);   
  123. var seconds = Math.floor(totalseconds)%60;   
  124. if (seconds<10) {   
  125.  seconds = "0"+seconds;   
  126. }   
  127. var playedseconds:Number = my_sound.position/1000;   
  128. var minutesed:Number = Math.floor(playedseconds/60);   
  129. var secondsed = Math.floor(playedseconds)%60;   
  130. if (secondsed<10) {   
  131.  sec+secondsed;   
  132. }   
  133. shijian_txt.text = minutesed+":"+secondsed+"—"+minutes+":"+seconds+"(Flash8.net闪吧)";   
  134. }; 

Tags:AS 简单 MP

编辑录入:coldstar [复制链接] [打 印]
赞助商链接