连接旋律并创建实例的形式的代码..
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;
}
请帮我
最佳答案
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);
}