在 Adobe AIR 中嵌入声音文件时出现问题
如果我使用 flash.media.Sound 类,我可以在 Adobe AIR 中播放声音文件,但我需要一个 URL 来执行此操作。我需要做的是将其作为嵌入资产加载到 AIR 应用程序中。我尝试过使用 mx.core.media 库,但这也不起作用。
这是一个显示问题的简单应用程序:
<fx:Script>
<![CDATA[
// Embed MP3 file.
import flash.media.Sound;
import mx.core.SoundAsset;
[Embed(source="ding.mp3")]
[Bindable]
public var sndCls:Class;
private var myReq:URLRequest = new URLRequest("ding.mp3");
private var snd:Sound;
private var sndAsset:Sound;
private var myChannel:SoundChannel;
protected function myButton_clickHandler(event:MouseEvent):void
{
sndAsset = new sndCls() as SoundAsset;
myChannel = sndAsset.play();
}
protected function myReqButton_clickHandler(event:MouseEvent):void
{
snd = new Sound(myReq);
snd.play();
}
]]>
</fx:Script>
<fx:Declarations>
</fx:Declarations>
<s:Button id="myButton" label="Play Embedded" click="myButton_clickHandler(event)"/>
<s:Button id="myReqButton" label="Play Requested" click="myReqButton_clickHandler(event)"/>
您需要在同一目录下添加 ding.mp3 来测试它。
欢迎任何建议
谢谢
史蒂夫
I can play a sound file in Adobe AIR if I use the the flash.media.Sound class but I have request a URL to do it. What I need to do is load it as an embedded asset in the AIR app. I have tried using mx.core.media library but this does not work either.
Here is a simple app that shows the problem:
<fx:Script>
<![CDATA[
// Embed MP3 file.
import flash.media.Sound;
import mx.core.SoundAsset;
[Embed(source="ding.mp3")]
[Bindable]
public var sndCls:Class;
private var myReq:URLRequest = new URLRequest("ding.mp3");
private var snd:Sound;
private var sndAsset:Sound;
private var myChannel:SoundChannel;
protected function myButton_clickHandler(event:MouseEvent):void
{
sndAsset = new sndCls() as SoundAsset;
myChannel = sndAsset.play();
}
protected function myReqButton_clickHandler(event:MouseEvent):void
{
snd = new Sound(myReq);
snd.play();
}
]]>
</fx:Script>
<fx:Declarations>
</fx:Declarations>
<s:Button id="myButton" label="Play Embedded" click="myButton_clickHandler(event)"/>
<s:Button id="myReqButton" label="Play Requested" click="myReqButton_clickHandler(event)"/>
You need ding.mp3 in the same directory to test it.
Any suggestions welcome
Thanks
Steve
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嵌入资源不能绑定,因为它是常量。尝试删除[可绑定]。如果这没有帮助,请发布错误消息(如果有)或描述问题的症状。
Embedded resource cannot be bindable, since it is constant. Try to remove [Bindable]. If that doesn't help, post error messages (if any) or describe symptoms what's wrong.