AAC / MP4不工作在ActionScript 3的的NetStream工作、AAC、ActionScript、NetStream

2023-09-09 21:48:27 作者:良辰未赏透

我想在Flash CS3中发挥远程AAC文件中的ActionScript 3,我目前使用这种code:

I'm trying to play a remote AAC file in ActionScript 3 in Flash CS3 and am currently using this code:

变种网址:字符串=htt​​p://a1.phobos.apple.com/us/r1000/020/Music/d4/50/94/mzm.kjjofihr.aac.p.m4a; VAR connect_nc:的NetConnection =新的NetConnection(); connect_nc.connect(空); VAR stream_ns:NetStream的=新的NetStream(connect_nc); stream_ns.play(URL);

var url:String = "http://a1.phobos.apple.com/us/r1000/020/Music/d4/50/94/mzm.kjjofihr.aac.p.m4a"; var connect_nc:NetConnection = new NetConnection(); connect_nc.connect(null); var stream_ns:NetStream = new NetStream(connect_nc); stream_ns.play(url);

(这是基于:的http://www.adobe.com/devnet/flashplayer/articles/hd_video_flash_player_03.html)

不会引发任何错误,但没有播放声音。我得到一个本地的AAC文件,并与当地的MP4视频相同的行为。

No errors are thrown, but no sound is played. I get the same behavior with a local AAC file and with a local MP4 video.

如果我用一个网址或文件路径不是一个流化文件,我得到一个NetStream.Play.StreamNotFound错误,我猜意味着流在一个有效的URL的情况下找到。如果我使用本地FLV,其音频播放就好了。

If I use a URL or file path that isn't a streamable file, I get a NetStream.Play.StreamNotFound error, which I'm guessing means that the stream is found in the case of a valid URL. If I use a local FLV, its audio is played just fine.

如果我的netStatusHandler添加下面的监听器和跟踪(evt.info。code),我只看到任何codeS(如NetStream.Play.Start)被曝与FLV。 C $ CS没有$被跟踪的AAC或MP4。 stream_ns.addEventListener(NetStatusEvent.NET_STATUS,的netStatusHandler);

If I add the following listener and trace(evt.info.code) in netStatusHandler, I only see any codes (e.g. NetStream.Play.Start) traced with the FLV. No codes are traced with the AAC or MP4. stream_ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

同样是加入这个监听器(即onMetaData参数只跟踪与FLV,不与其他文件类型),与定义为对象的追踪它的参数的调用onMetaData方法metaDataListener也是如此。 stream_ns.client = metaDataListener;

The same is true of adding this listener (i.e. the onMetaData argument is only traced with the FLV, not with the other file types), with metaDataListener defined as an object with an onMetaData method that traces its argument. stream_ns.client = metaDataListener;

的可能什么错在这里,或如何诊断呢?任何想法

Any ideas of what might be going wrong here, or how to diagnose it?

谢谢!

推荐答案

在ActionScript 3.0中一切都基于事件(与在回调中使用一些随机的例外)。

Everything in ActionScript 3.0 is event based (with few random exceptions where callbacks are used).

您需要用信息。code值为NetConnection.Connect.Success,以便在将NetStatusEvent听取被允许调用NetStream.play()函数。

You need to listen for the NetStatusEvent with info.code "NetConnection.Connect.Success" in order to be allowed to call the NetStream.play() function.

下面是一些作品(我只是写了,并测试它给你):

Here's something that works (I just wrote it now, and tested it for you):

package
{
    import flash.display.Sprite;

    import flash.net.NetConnection;
    import flash.net.NetStream;

    import flash.events.NetStatusEvent;
    import flash.events.AsyncErrorEvent;
    import flash.events.Event;

    public class MainDocument extends Sprite
    {
        private var _connection:NetConnection=new NetConnection();
        private var _netStream:NetStream=null;

        private var _strM4AURL:String="http://a1.phobos.apple.com/us/r1000/020/Music/d4/50/94/mzm.kjjofihr.aac.p.m4a";

        //constructor
        public function MainDocument():void
        {
            this._connect();
        }

        private function _connect():void
        {
            this._connection.close();
            this._connection=new NetConnection();
            this._connection.addEventListener(NetStatusEvent.NET_STATUS, this._netStatusHandler);
            this._connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, this._asyncErrorHandler);

            this._connection.connect(null);
        }

        private function _netStatusHandler(event:NetStatusEvent):void
        {
            trace(event.info.code);
            switch (event.info.code)
            {
                case "NetConnection.Connect.Success":
                    this._requestAudio();
                    break;
            }
        }

        private function _requestAudio():void
        {
            if(this._netStream!==null)
                this._netStream.close();

            this._netStream=new NetStream(this._connection);

            this._netStream.addEventListener(NetStatusEvent.NET_STATUS, this._netStatusHandler);
            this._netStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, this._asyncErrorHandler);

            this._netStream.checkPolicyFile=false;

            this._netStream.play(this._strM4AURL);
        }

        private function _asyncErrorHandler(event:AsyncErrorEvent):void
        {
            trace(event);
        }
    }
}

咨询ActionScript 3.0语言参考以了解更多信息。

Consult the ActionScript 3.0 Language Reference for more information.