[转载]AS3循环播放多个音乐


1 package
2 {
3 import flash.display.Sprite;
4 import flash.events.Event;
5 import flash.events.KeyboardEvent;
6 import flash.media.Sound;
7 import flash.media.SoundChannel;
8 import flash.net.URLRequest;
9 /**
10 * ...
11 * @author gangzi
12 */
13 public class LoopMore extends Sprite
14 {
15 private var music_array:Array;
16 private var music_index:uint;
17 private var urlrequest:URLRequest;
18 private var sound:Sound;
19 private var soundchannel:SoundChannel;
20
21 public function LoopMore()
22 {
23 init();
24 }
25
26 private function init():void
27 {
28 music_array = new Array();
29 music_index = 0;
30 urlrequest = new URLRequest();
31 sound = new Sound();
32 soundchannel = new SoundChannel();
33
34 music_array[0] = "1.mp3";
35 music_array[1] = "2.mp3";
36 music_array[2] = "3.mp3";
37
38 loadmusic();
39 }
40
41 private function loadmusic():void
42 {
43 urlrequest.url = music_array[music_index];
44 sound = new Sound();
45 sound.load(urlrequest);
46 trace("Load start");
47 sound.addEventListener(Event.COMPLETE, startPlay);
48 }
49
50 private function startPlay(e:Event):void
51 {
52 trace("Play start");
53 soundchannel = sound.play();
54 soundchannel.addEventListener(Event.SOUND_COMPLETE,playEnd);
55 }
56
57 private function playEnd(e:Event):void
58 {
59 trace("Play End");
60 music_index = (music_index < music_array.length - 1) ? music_index + 1:music_index = 0;
61 loadmusic();
62 }
63
64 }
65
66 }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值