public MainPage() { InitializeComponent(); _mediaPlayerHandle = new MediaPlayerHandle(Dispatcher); _mediaPlayerHandle.MessageReceivedFromBackground += OnMessageReceivedFromBackground; _mediaPlayerHandle.CurrentStateChanged += OnCurrentStateChanged; NavigationCacheMode = NavigationCacheMode.Required; _timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(0.6) }; var count = 0; _timer.Tick += (sender, o) => { var mediaPlayer = MediaPlayer; if (null == mediaPlayer) { return; } var positionText = string.Empty; try { var position = mediaPlayer.Position; positionText = position.ToString("G"); } catch (Exception ex) { Debug.WriteLine("MainPage position update failed: " + ex.Message); // The COM object is probably dead... CleanupFailedPlayer(); } txtPosition.Text = positionText; if (++count < 5) { return; } count = 0; _mediaPlayerHandle.NotifyBackground(BackgroundNotificationType.Memory); }; }
public MainPage() { InitializeComponent(); _mediaPlayerHandle = new MediaPlayerHandle(Dispatcher); _mediaPlayerHandle.MessageReceivedFromBackground += OnMessageReceivedFromBackground; _mediaPlayerHandle.CurrentStateChanged += OnCurrentStateChanged; NavigationCacheMode = NavigationCacheMode.Required; _timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(0.6) }; var count = 0; _timer.Tick += (sender, o) => { var mediaPlayer = MediaPlayer; if (null == mediaPlayer) return; var positionText = string.Empty; try { var position = mediaPlayer.Position; positionText = position.ToString("G"); } catch (Exception ex) { Debug.WriteLine("MainPage position update failed: " + ex.Message); // The COM object is probably dead... CleanupFailedPlayer(); } txtPosition.Text = positionText; if (++count < 5) return; count = 0; _mediaPlayerHandle.NotifyBackground(BackgroundNotificationType.Memory); }; }
public static void NotifyBackground(this MediaPlayerHandle handle, SystemMediaTransportControlsButton button) { handle.NotifyBackground(BackgroundNotificationType.Smtc, button.ToString()); }