Actionscript 3 NetStream立即暂停未获取元数据

发布于 2024-09-25 04:10:38 字数 354 浏览 6 评论 0原文

我正在 Flash CS5 和 Actionscript 3 中编写一个基本视频播放器。对于这个基本播放器,我将 NetStream 连接到 NetConnection,然后调用流的 .play() 方法开始加载。尽管我希望元数据和流开始缓冲,但我不希望立即开始播放,因此我立即调用流的 .pause() 方法。不幸的是,当我立即暂停时,我的流客户端的 onMetaData 事件并不总是被调用,因此我不一定获得已加载视频的总播放时间。

作为解决方法,我将对“pause”方法的调用放在 onMetaData 侦听器中,但有时我的视频在接收元数据之前会播放一段时间,因此会继续播放直到接收元数据。

有没有一种好方法可以阻止我的流播放,同时仍然获取我的视频元数据?

I am writing a basic video player in Flash CS5 and Actionscript 3. For this basic player, I attach my NetStream to my NetConnection, then call the stream's .play() method to begin loading. Although I want the metadata and for the stream to begin buffering, I do not wish to start playing right away, so I immediately call the stream's .pause() method. Unfortunately, when I pause immediately, my stream's client's onMetaData event is not always called, so I don't necessarily get the total playtime of the loaded video.

As a workaround, I put the call to the "pause" method inside the onMetaData listener, but sometimes my video will have played a bit before receiving it's metadata, and will therefore continue to play until it does.

Is there a good way to stop my stream from playing, and still get my video metadata?

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

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

发布评论

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

评论(2

深者入戏 2024-10-02 04:10:38

好的,这是一个以不同方式思考这个问题的巧妙小方法...不要立即将视频对象附加到流对象。开始播放流,同时显示“请稍候”视觉效果,但不显示视频对象。在您的 onMetaData 侦听器中,查看您之前是否存储了持续时间。如果不是,则假设这是第一次调用 onMetaData,存储持续时间,暂停播放,将流查找到 0,然后附加视频对象。

用户将看到“请稍候”一秒钟,然后视频将出现、暂停并播放。准备好按预期播放它的持续时间。用户在等待时完全不会意识到流向前播放了一点。

Okay, here's a neat little way of thinking about this differently... Do not attach your video object to your stream object right away. Start your stream playing while showing a "please wait" visual WITHOUT your video object being displayed. In your onMetaData listener, see if you have stored a duration previously. If not, assume this is the first call to onMetaData, store the duration, pause playback, seek the stream to 0, THEN attach the video object.

The user will see a "please wait" for just a sec, then the video will appear, paused & ready to be played with it's duration times as expected. The user will be completely unaware that the stream played forward a bit while they were waiting.

救星 2024-10-02 04:10:38

您应该在触发 NetStatusEvent.STATUS 事件 NetStream.Play.Start 时调用暂停。

更新:

对于非常短的流(例如buffer>durationNetStream.Play.Start可能会得到在 onMetaData 回调之前触发。

NetStream.Play.Start 暂停之前,检查是否已提供元数据,如果没有,不要直接暂停,而是等待 onMetaData 暂停(只需设置一个标志,例如 <代码>pauseOnMetaData = true)。

You should call pause when the NetStatusEvent.STATUS event NetStream.Play.Start is fired.

Update:

For very short streams (e.g. buffer > duration) NetStream.Play.Start is likely to get fired just before the onMetaData callback.

Before pausing on NetStream.Play.Start, check if metaData has been provided, if not don't pause straight but await onMetaData to pause (just set a flag, e.g pauseOnMetaData = true).

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