gpt4 book ai didi

actionscript-3 - 如何在ActionScript 3.0中为音乐播放器创建EASY自定义搜索栏

转载 作者:行者123 更新时间:2023-12-02 23:06:07 25 4
gpt4 key购买 nike

连接旋律并创建实例的形式的代码..

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);
}

关于actionscript-3 - 如何在ActionScript 3.0中为音乐播放器创建EASY自定义搜索栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43493967/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com