"Cannot decode" error after to instantiate multiple AVPlayer

flchauxflchaux FRMember ✭✭
edited November 2017 in Xamarin.iOS

My app is compound of 2 pages : one list and one detail containing multiple video players. After opening some details, and instancing about 12 AVPlayers, the player fails to load item with the error "Cannot decode". After the first fail, any players failed. I saw on StackOverflow there is a limit of decoder instances. I checked the AVPlayer has been disposed each time I come back to the list so I don't understand why I seems reach the limit.

Some pieces of code

Constructor:

public UIVideoPlayer() : base(new CGRect(0, 0, 0, 0))
{
    player = new AVPlayer();
    PlayerLayer = AVPlayerLayer.FromPlayer(player);
    Layer.AddSublayer(PlayerLayer);
}

URL Loading:

...
AVPlayerItem item = new AVPlayerItem(url);
player.ReplaceCurrentItemWithPlayerItem(item);
player.CurrentItem.AddObserver(this, "status", NSKeyValueObservingOptions.New, Handle);
...

Disposing:

protected override void Dispose(bool disposing)
{
    if (player.CurrentItem != null)
    {
        player.CurrentItem.RemoveObserver(this, "status");
        player.CurrentItem.Dispose();
    }
    player.Dispose();
    player = null;
    surfaceHolder = null;

    base.Dispose(disposing);
}

Can you help me ?

Florian.

Best Answer

  • flchauxflchaux FR ✭✭
    Accepted Answer

    I forgot to dispose the AVPlayerLayer ! Don't forget if you don't want to lose few days of work !

Answers

  • flchauxflchaux FRMember ✭✭
    Accepted Answer

    I forgot to dispose the AVPlayerLayer ! Don't forget if you don't want to lose few days of work !

Sign In or Register to comment.