Playing many different videos on iphone using AVPlayer

早过忘川 提交于 2019-11-27 12:57:33

I FINALLY SOLVED IT. The design I had was indeed very poor, It had a very bad memory management and so on. What I did was, instead of releasing everything I could, including views, layers, players, assets, etc, I just created a method to update the player's asset and item, recycling the player, views, layers, etc.

    [player pause];
    contentURL = [[NSURL alloc] initFileURLWithPath:newPath];
    AVAsset *newAsset = [AVURLAsset URLAssetWithURL:contentURL options:nil];
    AVPlayerItem *newPlayerItem = [AVPlayerItem playerItemWithAsset:newAsset];
    [player replaceCurrentItemWithPlayerItem:newPlayerItem];
    [contentURL release];

And now it's working wonders. Thank you all for your help.

There are 2 places in the code where you have retained an object, and I don't see the corresponding release anywhere in the code you have posted. I would start by making sure that the memory reference count increments and decrements are all appropriately balanced.

The first retain looks suspicious to me. Generally you should first autorelease the variable you are assigning to and then retain as follows:

[systemPath autorelease];
systemPath = [aContentURL retain]

In the above code is easy to see that the retain/release matching is maintained, and is far less error prone than other schemes. Note that if systemPath == aContentURL the object will not be released.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!