NetStream Flash AS3 - 视频缩短,没有说明原因

发布于 2024-10-28 10:10:57 字数 1880 浏览 2 评论 0原文

我一天中大部分时间都在寻找这个答案,但发现的问题多于答案。

我有一个 .exe 全屏 Flash 应用程序,可以通过外部源加载视频文件(以及许多其他内容)。一切都正常,只是当视频播放时,它经常被切断并停止播放。停止播放的位置是随机的。有时不到 2 秒,有时会持续 30 秒,但从未制作过完整的 58 秒视频。

我已经跟踪了加载的字节总数,并且它们匹配(这是本地引用的文件,没有网络)。

这是代码。如果有更好的方法来做到这一点(不涉及课程),请帮忙。

    function loadCaseVideo(sourceVideo:String):void {
//sourceVideo = reference link from XML data
    if(!videoLoadedAlready){
        var videoLoadedAlready:Boolean;
    }
    NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
    var mNetConnection:NetConnection=new NetConnection();
    mNetConnection.connect(null);
    var mNetStream = new NetStream(mNetConnection);
    var video = new Video();
    video.width = 728;
    video.height = 522;
    video.y = 0;
    video.x = 0;

    video.attachNetStream(mNetStream);
    videoHolder.videoInner.addChild(video);

    mNetStream.client=new Object();
    mNetStream.bufferTime=60;
    mNetStream.play(sourceVideo);       
    mNetStream.addEventListener(NetStatusEvent.NET_STATUS, onNetStreamStatusEvent);

    function onNetStreamStatusEvent(event:NetStatusEvent):void 
    {
        trace(event.info.code);
            if (event.info.code == "NetStream.Play.Start") 
            {
                //trace("NetStream.Play.Start");
                //trace(mNetStream.bytesLoaded +", " + mNetStream.bytesTotal);
            }
            if (event.info.code == "NetStream.Play.StreamNotFound") 
            {
                    //trace("Video Not Found");     
            }   
            if (event.info.code == "NetStream.Buffer.Flush")
            {
//I saw this being called so I ran a trace on it, these two are equal, meaning fully loaded?
                trace('loaded: '+ mNetStream.bytesLoaded +", total: " + mNetStream.bytesTotal);
            }
    }

    function onMetaData(metadata:Object):void
    {
    }




 }

I've searched most of the day for this answer, but found more questions than answers.

I have a .exe fullscreen flash app that loads video files (and many other things) through an external source. Everything links up okay, except that when the video plays, it often cuts out and just stops playing. Where it stops playing is random. Sometimes it's under 2 seconds, sometimes it will go for 30 seconds, but never has it made the full 58 seconds of the video.

I have traced the bytes loaded to the total and they match (it's a locally referenced file, no web).

Here's the code. If there's a better way to do this (that doesn't involve a class), please help.

    function loadCaseVideo(sourceVideo:String):void {
//sourceVideo = reference link from XML data
    if(!videoLoadedAlready){
        var videoLoadedAlready:Boolean;
    }
    NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
    var mNetConnection:NetConnection=new NetConnection();
    mNetConnection.connect(null);
    var mNetStream = new NetStream(mNetConnection);
    var video = new Video();
    video.width = 728;
    video.height = 522;
    video.y = 0;
    video.x = 0;

    video.attachNetStream(mNetStream);
    videoHolder.videoInner.addChild(video);

    mNetStream.client=new Object();
    mNetStream.bufferTime=60;
    mNetStream.play(sourceVideo);       
    mNetStream.addEventListener(NetStatusEvent.NET_STATUS, onNetStreamStatusEvent);

    function onNetStreamStatusEvent(event:NetStatusEvent):void 
    {
        trace(event.info.code);
            if (event.info.code == "NetStream.Play.Start") 
            {
                //trace("NetStream.Play.Start");
                //trace(mNetStream.bytesLoaded +", " + mNetStream.bytesTotal);
            }
            if (event.info.code == "NetStream.Play.StreamNotFound") 
            {
                    //trace("Video Not Found");     
            }   
            if (event.info.code == "NetStream.Buffer.Flush")
            {
//I saw this being called so I ran a trace on it, these two are equal, meaning fully loaded?
                trace('loaded: '+ mNetStream.bytesLoaded +", total: " + mNetStream.bytesTotal);
            }
    }

    function onMetaData(metadata:Object):void
    {
    }




 }

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

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

发布评论

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

评论(1

骄傲 2024-11-04 10:10:57

我能够通过以下方式解决此问题:

  1. 剥离所有内容
  2. 将 FLVPlayback 对象添加到我的影片剪辑(保存布局)中,

当时间线到达此帧时调用此函数:

function loadCaseVideo(sourceVideo:String):void {
    videoHolder.videoPlayer.width = 728;
    videoHolder.videoPlayer.height = 522;
    videoHolder.videoPlayer.x = 0;
    videoHolder.videoPlayer.y = 0;
    videoHolder.videoPlayer.fullScreenTakeOver = false;
    videoHolder.videoPlayer.scaleMode = "exactFit";
    videoHolder.videoPlayer.source = sourceVideo;
 }

当不处​​理流式网络时,这似乎是最好的方法做这个。我曾尝试首先使用这个组件,但当时我也在解决为什么 f4v 无法工作的问题 - 这是因为我使用的是旧版本的 Flash。当我使用 CS5 后,该组件就按照 f4v 的预期为我工作了。

  • 仅桌面
  • 动态源可以
  • 如果您的应用程序是全屏的,请确保将 fullScreenTakeOver 设置为 false,否则视频将在您的应用程序中全屏显示。

I was able to resolve this by:

  1. Stripping everything back out
  2. Adding an FLVPlayback Object to my movieclip (that held the layout)

calling this function when the timeline reached this frame:

function loadCaseVideo(sourceVideo:String):void {
    videoHolder.videoPlayer.width = 728;
    videoHolder.videoPlayer.height = 522;
    videoHolder.videoPlayer.x = 0;
    videoHolder.videoPlayer.y = 0;
    videoHolder.videoPlayer.fullScreenTakeOver = false;
    videoHolder.videoPlayer.scaleMode = "exactFit";
    videoHolder.videoPlayer.source = sourceVideo;
 }

When NOT DEALING WITH STREAMING WEB, this seemed to be the best way to do this. I had tried to use this component first, but at that time I was also resolving why f4v wasn't working - which was because I was in an older version of Flash. Once I was using CS5, the component worked for me as expected with f4v's.

  • Desktop only
  • Dynamic sources ok
  • If your app is fullscreen, make sure you set fullScreenTakeOver to false or the video will fullscreen in your app.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文