AAC/MP4 无法在 ActionScript 3 的 NetStream 中工作

发布于 2024-08-18 01:43:08 字数 1259 浏览 2 评论 0原文

我正在尝试在 Flash CS3 中的 ActionScript 3 中播放远程 AAC 文件,目前正在使用以下代码:

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 视频也有相同的行为。

如果我使用不是可流式传输文件的 URL 或文件路径,则会收到 NetStream.Play.StreamNotFound 错误,我猜测这意味着在有效 URL 的情况下找到了流。如果我使用本地 FLV,它的音频播放得很好。

如果我在 netStatusHandler 中添加以下侦听器和跟踪(evt.info.code),我只会看到使用 FLV 跟踪的任何代码(例如 NetStream.Play.Start)。 AAC 或 MP4 无法追踪任何代码。 Stream_ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

添加此侦听器也是如此(即 onMetaData 参数仅使用 FLV 进行跟踪,而不使用其他文件类型进行跟踪),并将 metaDataListener 定义为具有 onMetaData 方法的对象,该方法可跟踪其参数。
Stream_ns.client=metaDataListener;

关于这里可能出了什么问题或者如何诊断它的任何想法?

谢谢!

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


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

(This is based on: http://www.adobe.com/devnet/flashplayer/articles/hd_video_flash_player_03.html)

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.

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.

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

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?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一抹苦笑 2024-08-25 01:43:08

如此处所述 http://www.adobe.com/devnet/flashplayer/articles /hd_video_flash_player_03.html 您所做的事情是正确的。

var connect_nc:NetConnection = new NetConnection();
connect_nc.connect(null);
var stream_ns:NetStream = new NetStream(connect_nc);
stream_ns.play("RE-Sample.m4a");

然而,关于 nestream 的 Actionscript 语言参考可以在这里找到:
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/net/NetStream.html#play%28%29" adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/net/NetStream.html#play%28%29

声明:

play() 方法

……

当您在没有 Flash Media 的情况下使用此方法 服务器方面,还有安全方面的考虑。本地可信沙箱或本地联网沙箱中的文件可以加载并播放远程沙箱中的视频文件,但如果没有跨域策略文件形式的明确许可,则无法访问远程文件的数据。此外,您还可以通过设置对象的allowNetworking 参数并在包含SWF 内容的HTML 页面中嵌入标记来阻止在Flash Player 中运行的SWF 文件使用此方法。

...
...

参数
... 参数 — 要播放的视频文件的位置,作为 URLRequest 对象或字符串。在 Flash Player 和应用程序安全沙箱之外的 AIR 内容中,您可以播放存储在与 SWF 文件相同的目录或子目录中的本地视频文件;但是,您无法导航到更高级别的目录。

所以这可能是一个安全沙箱问题。

As stated here http://www.adobe.com/devnet/flashplayer/articles/hd_video_flash_player_03.html what you are doing is correct.

var connect_nc:NetConnection = new NetConnection();
connect_nc.connect(null);
var stream_ns:NetStream = new NetStream(connect_nc);
stream_ns.play("RE-Sample.m4a");

However, the Actionscript Language reference about nestream found here:
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/net/NetStream.html#play%28%29

states that:

play () method

...

...

When you use this method without Flash Media Server, there are security considerations. A file in the local-trusted or local-with-networking sandbox can load and play a video file from the remote sandbox, but cannot access the remote file's data without explicit permission in the form of a cross-domain policy file. Also, you can prevent a SWF file running in Flash Player from using this method by setting the allowNetworking parameter of the the object and embed tags in the HTML page that contains the SWF content.

...
...

Parameters
... arguments — The location of the video file to play, as a URLRequest object or a string. In Flash Player and in AIR content outside of the application security sandbox, you can play local video files that are stored in the same directory as the SWF file or in a subdirectory; however, you can't navigate to a higher-level directory.

So it's probably a security sandbox issue.

月下凄凉 2024-08-25 01:43:08

ActionScript 3.0 中的所有内容都是基于事件的(很少有使用回调的随机例外)。

您需要使用 info.code“NetConnection.Connect.Success”监听 NetStatusEvent,以便允许调用 NetStream.play() 函数。

下面是一些可行的东西(我现在刚刚编写它,并为您进行了测试):

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 语言参考以获取更多信息。

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

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

Consult the ActionScript 3.0 Language Reference for more information.

缘字诀 2024-08-25 01:43:08

Oliver 所说的很有可能是真的,因为您没有从与 NetStream 关​​联的任何事件侦听器获得任何反馈,并且您收到了 StreamNotFound 响应。

StreamNotFound 当未连接到 FMS 时意味着您的路径错误或由于安全问题而没有看到它。

There's a good chance what Oliver is saying is true as your not getting any feedback from any event listeners associated with the NetStream, and you are getting a StreamNotFound response.

StreamNotFound when not connecting to a FMS means that you either have the path wrong or its not seeing it, due to a security issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文