Playing many different videos on iphone using AVPlayer

后端 未结 2 431
攒了一身酷
攒了一身酷 2020-12-03 01:59

I\'m working on a custom video player for iOS using AVFoundation. The idea is to be able to switch to a different video with a gesture (tap, swipe, whatever). Right

相关标签:
2条回答
  • 2020-12-03 02:50

    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.

    0 讨论(0)
  • 2020-12-03 03:00

    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.

    0 讨论(0)
提交回复
热议问题