Beispiel #1
0
        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());
 }
Beispiel #3
0
        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);
            };
        }
Beispiel #4
0
        void gcButton_Click(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("MainPage gc");

            _mediaPlayerHandle.NotifyBackground(BackgroundNotificationType.Gc);
        }