在Adobe AIR中嵌入声音文件时出现问题

在Adobe AIR中嵌入声音文件时出现问题,air,adobe,audio,Air,Adobe,Audio,如果我使用flash.media.sound类,我可以在AdobeAIR中播放声音文件,但我需要一个URL来执行此操作。我需要做的是将其作为嵌入式资产加载到AIR应用程序中。我尝试过使用mx.core.media库,但这也不起作用 <fx:Script> <![CDATA[ // Embed MP3 file. import flash.media.Sound; import mx.core.SoundAsset;

如果我使用flash.media.sound类,我可以在AdobeAIR中播放声音文件,但我需要一个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)"/>
下面是一个显示问题的简单应用程序:

<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)"/>

<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来测试它

<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)"/>
欢迎提出任何建议

<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)"/>
谢谢

<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)"/>

Steve

嵌入式资源不能绑定,因为它是常量。尝试删除[Bindable]。如果这没有帮助,发布错误消息(如果有的话)或描述症状

<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)"/>