Flash 播放器在循环播放电影时崩溃

发布于 2024-10-18 05:26:56 字数 1244 浏览 3 评论 0原文

我正在尝试在 Flash 中实现某种幻灯片放映,它会循环播放大约 100 个 h.264 编码的电影。我正在使用 NetConnection 和 NetStream 类连接到本地硬盘上的文件(请参阅下面的代码)。

private function playMovie():void
{           
        var currentMovie:String = movies[index];
        index = (index + 1) % movies.length;

        netConnection = new NetConnection();
        netConnection.connect(null);

        if(netStream != null)
        {
            netStream.removeEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);         
            netStream = null;
        }

        netStream = new NetStream(netConnection);
        netStream.client = this;
        netStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

        stageVideo.attachNetStream(null);
        stageVideo.attachNetStream(netStream);

        netStream.play(currentMovie);
}

private function netStatusHandler(evt:NetStatusEvent):void
{
        if(evt.info.code == "NetStream.Play.Stop")
        {
            playMovie();
        }
}

public function onMetaData(e:Object):void 
{
        netStream.seek(int(e["duration"]));
}       
public function onXMPData (e:Object):void {}

问题是 Flashplayer 的内存使用量随着每部电影的增加而增加,当达到大约 1.3GB 时,它就会自行结束,没有任何错误消息。

我的问题显然是:我该如何解决这个问题?

I'm trying to realize kind of a slideshow in flash, which loops over about 100 h.264 encoded movies. I'm using the NetConnection and NetStream classes for connecting to the files locally on my harddisk (see code below).

private function playMovie():void
{           
        var currentMovie:String = movies[index];
        index = (index + 1) % movies.length;

        netConnection = new NetConnection();
        netConnection.connect(null);

        if(netStream != null)
        {
            netStream.removeEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);         
            netStream = null;
        }

        netStream = new NetStream(netConnection);
        netStream.client = this;
        netStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

        stageVideo.attachNetStream(null);
        stageVideo.attachNetStream(netStream);

        netStream.play(currentMovie);
}

private function netStatusHandler(evt:NetStatusEvent):void
{
        if(evt.info.code == "NetStream.Play.Stop")
        {
            playMovie();
        }
}

public function onMetaData(e:Object):void 
{
        netStream.seek(int(e["duration"]));
}       
public function onXMPData (e:Object):void {}

the problem is that the memory usage of the flashplayer increases with every movie and when reaching about 1.3gb it just ends itself without any errormessage.

my question obviously: how can i fix that?

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

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

发布评论

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

评论(1

温柔一刀 2024-10-25 05:26:56

您必须调用 NetConnection.close() 来释放资源,否则您的内存使用量将会增加,如您所见。不过,更好的做法是,在创建后保留相同的 NetConnection 和 NetStream 对象来播放不同的视频:

private function playMovie():void
{           
    var currentMovie:String = movies[index];
    index = (index + 1) % movies.length;

    if ( netConnection == null ) 
    {
        netConnection = new NetConnection();
        netConnection.connect(null);
    }

    if ( netStream == null )
    {
        netStream = new NetStream(netConnection);
        netStream.client = this;
        netStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        stageVideo.attachNetStream(netStream);
    }

    netStream.play(currentMovie);
}

You must call NetConnection.close() to free the resources, otherwise your memory usage will increase as you see it. It is better practice, though, to keep the same NetConnection and NetStream objects, once created, to play different videos:

private function playMovie():void
{           
    var currentMovie:String = movies[index];
    index = (index + 1) % movies.length;

    if ( netConnection == null ) 
    {
        netConnection = new NetConnection();
        netConnection.connect(null);
    }

    if ( netStream == null )
    {
        netStream = new NetStream(netConnection);
        netStream.client = this;
        netStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        stageVideo.attachNetStream(netStream);
    }

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