连接旋律和创建实例的代码..
import flash.events.Event;
var mySound:Sound = new MyFavSong();
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0;
var myTransform = new SoundTransform();
myChannel = mySound.play();
myTransform.volume = 1;
myChannel.soundTransform = myTransform;
stop();
然后播放按钮,暂停,声音停止+音量 停止
stop_btn.addEventListener(MouseEvent.CLICK, onClickStop);
function onClickStop(e:MouseEvent):void{
myChannel.stop();
lastPosition = 0;
stop();
}
暂停
pause_btn.addEventListener(MouseEvent.CLICK, onClickPause);
function onClickPause(e:MouseEvent):void{
lastPosition = myChannel.position;
myChannel.stop();
stop();
}
播放
play_btn.addEventListener(MouseEvent.CLICK, onClickPlay);
function onClickPlay(e:MouseEvent):void{
myChannel = mySound.play(lastPosition);
myChannel.soundTransform = myTransform;
play();
}
量
up_btn.addEventListener(MouseEvent.CLICK, onClickUp);
function onClickUp(e:MouseEvent):void{
myChannel.soundTransform = myTransform;
myTransform.volume = myTransform.volume + 1;
}
请帮帮我
答案 0 :(得分:1)
soundChannel没有专门的进度事件,但您可以访问每帧的SoundChannel.position属性以获得当前声音位置(以毫秒为单位)。您可以通过将SoundChannel.position的值除以Sound.length值来获得搜索栏的比例。 见例:
var mySound: Sound = new MyFavSong();
var myChannel: SoundChannel = mySound.play();
var lastPosition: Number = 0;
var myTransform = new SoundTransform();
myTransform.volume = 1;
myChannel.soundTransform = myTransform;
stop();
var totalWidth: Number = stage.stageWidth;
var barContainer: Sprite = new Sprite();
var progressBar: Shape = new Shape();
var blankBar: Shape = new Shape();
initBlankBar();
barContainer.addChild(blankBar);
barContainer.addChild(progressBar);
barContainer.addEventListener(MouseEvent.CLICK, seekSound);
progressBar.addEventListener(Event.ENTER_FRAME, updateSoundProgress);
addChild(barContainer);
function initBlankBar(): void {
blankBar.graphics.beginFill(0xAAC7DB);
blankBar.graphics.drawRect(0, 0, totalWidth, 20);
blankBar.graphics.endFill();
}
function updateSoundProgress(e: Event): void {
var w: Number = (myChannel.position / mySound.length) * totalWidth;
progressBar.graphics.clear();
progressBar.graphics.beginFill(0xFF0000);
progressBar.graphics.drawRect(0, 0, w, 20);
progressBar.graphics.endFill();
}
function seekSound(e: MouseEvent):void {
lastPosition = (e.localX / totalWidth) * mySound.length;
onClickPlay(null);
}
function onClickPlay(e: MouseEvent): void {
myChannel.stop();
myChannel = mySound.play(lastPosition, 0, myTransform);
}