private async Task RefreshStateAsync()
{
await this._MediaPlayer.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
if (null == this._Controller || !this._Controller.IsValid)
return;
try
{
// get the active variant stream into a local variable to avoid null references as it's null briefly while switching bitrates
var activeVariantStream = this._Controller.Playlist.ActiveVariantStream;
if (null == activeVariantStream)
return;
if (null != this._Controller.Playlist && this._Controller.Playlist.IsMaster)
{
// value ranging from 0 to 1
this._MediaPlayer.SignalStrength = (0 == this._Controller.Playlist.MaximumAllowedBitrate) ? 0 :
(double)activeVariantStream.Bitrate / this._Controller.Playlist.MaximumAllowedBitrate;
// HLS has an optional resolution, only set media quality if the HLS stream specifies a resolution.
if (activeVariantStream.HasResolution)
this._MediaPlayer.MediaQuality = (720 <= activeVariantStream.VerticalResolution) ?
MediaQuality.HighDefinition : MediaQuality.StandardDefinition;
}
}
catch { }
});
}