Exemplo n.º 1
0
        private void Jukebox_MediaEvent(object sender, MediaActionEventArgs e)
        {
            switch (e.MediaActionFlags)
            {
            case MediaActionFlags.Play:
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Down, Keycode.MediaPlay));
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Up, Keycode.MediaPlay));
                break;

            case MediaActionFlags.Pause:
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Down, Keycode.MediaPause));
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Up, Keycode.MediaPause));
                OnPlaybackStateChanged(RemoteControlPlayState.Paused);     //Workaround: Manually Notifying that the media has been paused.
                //because Android is mediocre and won't do this, so my app won't know if the media was paused. //This could lead to some fun bugs, but
                //It's the best approach I have found.
                break;

            case MediaActionFlags.SkipToNext:
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Down, Keycode.MediaNext));
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Up, Keycode.MediaNext));
                break;

            case MediaActionFlags.SkipToPrevious:
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Down, Keycode.MediaPrevious));
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Up, Keycode.MediaPrevious));
                break;

            case MediaActionFlags.SeekTo:
                TransportControls.SeekTo(e.Time);
                break;

            case MediaActionFlags.FastFoward:
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Down, Keycode.MediaFastForward));
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Up, Keycode.MediaFastForward));
                break;

            case MediaActionFlags.Rewind:
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Down, Keycode.MediaRewind));
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Up, Keycode.MediaRewind));
                break;

            case MediaActionFlags.Stop:
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Down, Keycode.MediaStop));
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Up, Keycode.MediaStop));

                break;

            case MediaActionFlags.Replay:
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Down, Keycode.MediaStop));
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Up, Keycode.MediaStop));
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Down, Keycode.MediaPlay));
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Up, Keycode.MediaPlay));

                break;

            case MediaActionFlags.RetrieveMediaInformation:
                //Send media information.
                OnMediaMetadataChanged(new MediaMetadataChangedKitkatEventArgs
                {
                    Title    = MediaMetadata.GetString((MediaMetadataEditKey)MetadataKey.Title, ""),
                    Artist   = MediaMetadata.GetString((MediaMetadataEditKey)MetadataKey.Artist, ""),
                    Album    = MediaMetadata.GetString((MediaMetadataEditKey)MetadataKey.Album, ""),
                    AlbumArt = MediaMetadata.GetBitmap(MediaMetadataEditKey.BitmapKeyArtwork, null),
                    Duration = MediaMetadata.GetLong((MediaMetadataEditKey)MetadataKey.Duration, 0)
                });
                //Send Playbackstate of the media.
                OnMediaPlaybackChanged(new MediaPlaybackStateChangedKitkatEventArgs
                {
                    PlaybackState = PlaybackState,
                    CurrentTime   = CurrentMediaPosition,
                });

                break;

            default:
                break;
            }
        }
        private void Jukebox_MediaEvent(object sender, MediaActionEventArgs e)
        {
            switch (e.MediaActionFlags)
            {
            case MediaActionFlags.Play:
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Down, Keycode.MediaPlay));
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Up, Keycode.MediaPlay));
                break;

            case MediaActionFlags.Pause:
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Down, Keycode.MediaPause));
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Up, Keycode.MediaPause));
                break;

            case MediaActionFlags.SkipToNext:
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Down, Keycode.MediaNext));
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Up, Keycode.MediaNext));
                break;

            case MediaActionFlags.SkipToPrevious:
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Down, Keycode.MediaPrevious));
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Up, Keycode.MediaPrevious));
                break;

            case MediaActionFlags.SeekTo:
                TransportControls.SeekTo(e.Time);
                break;

            case MediaActionFlags.FastFoward:
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Down, Keycode.MediaFastForward));
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Up, Keycode.MediaFastForward));
                break;

            case MediaActionFlags.Rewind:
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Down, Keycode.MediaRewind));
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Up, Keycode.MediaRewind));
                break;

            case MediaActionFlags.Stop:
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Down, Keycode.MediaStop));
                TransportControls.SendMediaKeyEvent(new KeyEvent(KeyEventActions.Up, Keycode.MediaStop));

                break;

            case MediaActionFlags.RetrieveMediaInformation:
                //Send media information.
                OnMediaMetadataChanged(new MediaMetadataChangedKitkatEventArgs
                {
                    Title    = MediaMetadata.GetString((MediaMetadataEditKey)MetadataKey.Title, ""),
                    Artist   = MediaMetadata.GetString((MediaMetadataEditKey)MetadataKey.Artist, ""),
                    Album    = MediaMetadata.GetString((MediaMetadataEditKey)MetadataKey.Album, ""),
                    AlbumArt = MediaMetadata.GetBitmap(MediaMetadataEditKey.BitmapKeyArtwork, null),
                    Duration = MediaMetadata.GetLong((MediaMetadataEditKey)MetadataKey.Duration, 0)
                });
                //Send Playbackstate of the media.
                OnMediaPlaybackChanged(new MediaPlaybackStateChangedKitkatEventArgs
                {
                    PlaybackState = PlaybackState,
                    CurrentTime   = CurrentMediaPosition,
                });

                break;

            default:
                break;
            }
        }