[AS3]as3做的XML超简单mp3音乐播放器源代码
[AS3]as3做的XML超简单mp3音乐播放器源代码
前几天做的mp3,背景图是我同学画的,本来想做好的,但又觉得没什么意思就做了这么点了,反正丢者也是丢者,就发上来给大家参考下把.测试时候有4个一样的按钮,我没弄了,大家可以按下,各有各的功能.加栽XML可以时时更新.
大家有什么不懂的可以提出来,.大家把文件放到同一文件夹,再建一个music文档,music文档里面分别放0.mp3,1.mp3,2.mp3,3.mp3,4.mp3就可以了
- name_txt.text = ;
- var num:Number = 0;
- /*CuPlayer.com建立XML对象*/
- var myXML:XML = new XML();
- /*CuPlayer.com忽略空白*/
- myXML.ignoreWhite = true;
- /*CuPlayer.com建立声音对象*/
- var mySound:Sound = new Sound();
- /*保存歌曲名字的数组*/
- var nameArray:Array = new Array();
- /*CuPlayer.com歌曲的地址*/
- var urlArray:Array = new Array();
- /*CuPlayer.com加载XML*/
- myXML.onLoad = function(success:Boolean) {
- if (success) {
- var root = this.firstChild;
- for (var i:Number = 0; i<root.childNodes.length; i++) {
- /*将歌曲名字和地址分别添加到数组中*/
- nameArray.push(root.childNodes[i].attributes.name);
- urlArray.push(root.childNodes[i].attributes.path);
- loadedfunc();
- }
- } else {
- trace(CuPlayer.com加载失败);
- }
- };
- /*加载音乐地址*/
- myXML.load(music_xml.xml);
- function loadedfunc() {
- mySound.loadSound(urlArray[0], false);
- /*加载完成*/
- mySound.onLoad = function() {
- this.start(0);
- };
- name_txt.text = nameArray[0];
- }
- /*CuPlayer.com按钮可以性*/
- play_btn.enabled = false;
- pause_btn.enabled = true;
- prev_btn.enabled = false;
- next_btn.enabled = true;
- /*CuPlayer.com开始按钮*/
- play_btn.onRelease = function() {
- pause_btn.enabled = true;
- if (pauseTime) {
- mySound.start(pauseTime);
- } else {
- mySound.start(0);
- }
- };
- /*CuPlayer.com暂停按钮*/
- pause_btn.onRelease = function() {
- play_btn.enabled = true;
- mySound.stop();
- pauseTime = mySound.position/1000;
- };
- /*CuPlayer.com下一曲按钮*/
- next_btn.onRelease = function() {
- numnum = num+1;
- prev_btn.enabled = true;
- if (num<urlArray.length) {
- mySound.loadSound(urlArray[num], false);
- mySound.start(0);
- name_txt.text = nameArray[num];
- } else {
- next_btn.enabled = false;
- }
- };
- /*上一曲按钮*/
- prev_btn.onRelease = function() {
- next_btn.enabled = true;
- numnum = num-1;
- if (num>=0) {
- mySound.loadSound(urlArray[num], false);
- mySound.start(0);
- name_txt.text = nameArray[num];
- } else {
- prev_btn.enabled = false;
- }
- };
- var states:Boolean = false;
- var vol:Number = 0;
- /*CuPlayer.com划块移动*/
- square_mc.onPress = function() {
- this.startDrag(false, 211.3, 160, 312.3, 160);
- };
- square_mcsquare_mc.onRelease = square_mc.onReleaseOutside=function () {
- stopDrag();
- };
- onEnterFrame = function () {
- vol = int(square_mc._x-211.3);
- volvol_txt.text = vol;
- /*CuPlayer.com调节音量*/
- mySound.setVolume(vol);
- };
XML
- <?xml version=1.0 encoding=UTF-8?>
- <music>
- <songs name=初恋情人 path=music/0.mp3/>
- <songs name=魅族 path=music/1.mp3/>
- <songs name=天意 path=music/2.mp3/>
- <songs name=暗里着迷 path=music/3.mp3/>
- <songs name=春天的味道 path=music/4.mp3/>
- </music>
热门文章推荐
- 纯HLS(m3u8)跨平台技术(HLSPlayer,m3u8Player跨平台多终端)
- DiscuzX3.2酷播视频插件(dz论坛自定义视频插件带广告
- [微信视频]实现网站中的视频在微信平台上正常播放(超多组图)
- [rtsp]海康威视监控摄像头实现web端无插件监控实拍效果
- 很酷,酷播wordpress视频插件(支持PC/安卓/苹果跨平台播放)
- [组图]微信视频技术:支持微信视频直播和视频点播
- [AS3]as3.0的rtmp流媒体播放器写法源代码示例
- 一步一步教你制作FLV网页视频播放器
请稍候...