我正试图在闪光灯中实现一种幻灯片放映,它可以循环播放约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时,它就会自动结束而没有任何错误消息。
显然我的问题是:如何解决这个问题?答案 0 :(得分:1)
您必须调用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);
}