The player framework has built in features to give you out of the box error handling and recovery as well as APIs to make it easy to implement custom error handling solutions.

Under the hood

The player framework relies on the MediaElement.MediaFailed event (for xaml & WP8) and the video tag’s error event (for JS) to receive notification that there was a critical problem that prevents playback of the stream. Note: non critical warnings that can be ignored do not cause these events to fire. Examples of things that will cause these events to fire are:
  • HTTP errors when downloading the media.
  • Non supported media formats (e.g. HLS streams).
  • Incorrect or corrupt media files (e.g. MP4 files with bad data).

Furthermore, the smooth streaming SDK has additional built in logic to help retry and recover when problems are encountered. For example, the smooth streaming SDK will automatically retry to download chunks during communication errors and after giving up will after 50 tries. If the smooth streaming SDK is unable to recover, the MediaElement and video tag will fire their respective error events and the player framework will take it from there.

Error handling features of the player framework

When the player framework does detect a failure, it will automatically hide the normal control strip and show an error screen to the user that contains a button to allow the user to retry.
retry.png
When the user clicks the retry button, the player framework puts the player in a retrying state, remember the position of playback and reset the source. If the source successfully opens, the player will seek to the last known good position of playback.

Detecting errors in the player framework

In Xaml & WP8:

The MediaFailed event will fire
The PlayerState will be set to Failed
The player’s visual state will be set to “Failed”
The PlayerStateChanged event will fire

In JS:

The failed event will fire
The playerState will be set to PlayerFramework.PlayerState.failed
The playerstatechange event will fire

What happens during a retry

In all versions (Xaml, WP8, and JS): MediaPlayer.Retry() is called to reload the media and set MediaPlayer.StartupPosition to the last known good position.

If the retry is unsuccessful, the media failure event sequence above will re-occur.

If the media was previously opened and the retry is successful, the player will resume playback from the previous position. Under the hood, the media to be closed and re-opened and all events and state changes that occur from closing and opening media will re-occur.

If the media was previously unopened and the retry is successful, the MediaOpened event will fire and the normal sequence of events that occur after opening the media will ensue.

Advanced: When accessing the Smooth Streaming SDK directly from your app

For advanced smooth streaming features, applications can access the Smooth Streaming SDK directly in your app. If you are doing this, you should consider that during a retry, the player framework nulls and resets the source on the MediaElement. While the player framework shelters your app from events that fire during this time, if you are directly listening for events such as the Opened and Closed events on the Smooth Streaming SDK objects, these will get raised during the retry process.

Last edited Jan 22, 2013 at 9:47 PM by timgreenfield, version 2