コード例 #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);
            };
        }
コード例 #2
0
ファイル: MainPage.xaml.cs プロジェクト: henricj/phonesm
        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);
            };
        }
コード例 #3
0
 public static void NotifyBackground(this MediaPlayerHandle handle, SystemMediaTransportControlsButton button)
 {
     handle.NotifyBackground(BackgroundNotificationType.Smtc, button.ToString());
 }