Troubleshooting AVPlayer With Xamarin On iOS

When you’re using AVPlayer with Xamarin one of the difficulties can be troubleshooting. There’s an easy way to get error notification from AVPlayer that isn’t mentioned in the Xamarin documentation.

You probably already have something similiar to this line:

_playerItem.AddObserver( this, "status", NSKeyValueObservingOptions.Initial | NSKeyValueObservingOptions.New, IntPtr.Zero );

To get notification of errors as well, just add this line in the same place:

_playerItem.AddObserver( this, "error", NSKeyValueObservingOptions.Initial | NSKeyValueObservingOptions.New, IntPtr.Zero );

These events can be seen in:

public override void ObserveValue( NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context )

In your playerItem, look in _playerItem.ErrorLog to see your error.

Bradley Dean's Picture

About Bradley Dean

Certified Xamarin Mobile Developer with experience in Xamarin Forms, Ionic, Cordova, Phone Gap, ASP.Net MVC, Web Services, and sarcasm.

Atlanta, GA http://truegeek.com