Creator2.14版本,发布IOS原生。
功能:播放本地视频。
现象:视频播放,多次换换视频资源,差的机子直接崩溃,好的机子会黑屏。
崩溃的机子报Message from debugger: Terminated due to memory issue错误。
应该是内存泄露,可是监听不到。
发现每次调用clip时,VideoPlayer会创建一个(IOS监听到),但没有发现释放的地方。
监听memory时,发现切换视频资源时,other progress的memory都会增长。
jsb-engine.js中setURL方法:
_p.setURL = function (path) {
var source = void 0,
extname = void 0;
if (this._url === path) {
return;
}
this.removeDom();
this._url = path;
this.createDomElementIfNeeded();
this._bindEvent();
var video = this._video;
if (!video) {
return;
}
video.setVisible(this._visible);
this._loaded = false;
this._played = false;
this._playing = false;
this._loadedmeta = false;
video.setURL(this._url);
};
removeDom方法是删除videoplayer,createDomElementIfNeeded创建videoplayer。
我的猜想:
removeDom并没有把AVPlayer(IOS)释放了,所以每次更改clip都会向系统请求AVPlayer。导致内存崩溃了。
修改想法:
removeDom应该上一个AVPlayer释放了(我不知道怎么弄
)
我的修改:
jsb-engine.js中
_p.setURL = function (path) {
var source = void 0,
extname = void 0;
if (this._url === path) {
return;
}
this._url = path;
var video = this._video;
if (!video) {
return;
}
video.setVisible(this._visible);
this._loaded = false;
this._played = false;
this._playing = false;
this._loadedmeta = false;
video.setURL(this._url);
};
_p.createDomElementIfNeeded = function () {
if (!jsb.VideoPlayer) {
cc.warn('VideoPlayer only supports mobile platform.');
return null;
}
if (!this._video) {
this._video = new jsb.VideoPlayer();
this._bindEvent();
}
};
VideoPlayer-ios.mm中
-(void) setURL:(int)videoSource :(std::string &)videoUrl
{
[self stop];
[self removePlayerEventListener];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:@(videoUrl.c_str())]];
if (self.playerController.player) {
[self.playerController.player replaceCurrentItemWithPlayerItem:playerItem];
}
else {
self.playerController.player = [AVPlayer playerWithPlayerItem:playerItem];
}
[self registerPlayerEventListener];
}
每次都只用一次AVPlayer,
新问题:切换资源后,无法监听到META_LOADED和READY_TO_PLAY事件;
有解决吗?我现在IOS崩溃也很高,内存占用很大
这个视频的内存问题已经解决,试试升级到2.3版本
修复 iOS 从后台切换前台 glContext 没切换导致崩溃的问题 #2083
是这个吗?手动合并行不行
是的,可以手动合并