我使用以下示例播放 MP3 文件(我不需要/想要“打开”对话框):
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">
<fx:Script>
<![CDATA[
import flash.media.*;
[Embed(source="assets/marseljeza.mp3")]
[Bindable]
public var sndCls:Class;
public var snd:Sound = new sndCls() as Sound;
public var sndChannel:SoundChannel;
public function playSound():void {
sndChannel=snd.play();
}
public function stopSound():void {
sndChannel.stop();
}
]]>
</fx:Script>
<s:HGroup>
<s:Button label="play" click="playSound();"/>
<s:Button label="stop" click="stopSound();"/>
</s:HGroup>
</s:View>`
点击播放按钮后,MP3文件播放正常,但如果我再次点击播放按钮,歌曲同时从头开始,如果我点击按钮三、四、五或更多,同样如此次。所以我最终得到了同一首歌的更多同时“会话”。我想在第一次单击后禁用 PLAY 按钮,并在单击 STOP 后再次启用相同的按钮。我怎样才能做到这一点?