public override void OnCreate()
        {
            base.OnCreate();
            _playingQueue  = new List <MediaSession.QueueItem>();
            _musicProvider = new MusicProvider();
            _packageFinder = new PackageFinder();
            _musicPlayer   = new MusicPlayer(this, _musicProvider);

            var mediaCallback = this.CreateMediaSessionCallback();

            _session     = new MediaSession(this, "HenryPodcast");
            SessionToken = _session.SessionToken;
            _session.SetCallback(mediaCallback);
            _session.SetFlags(MediaSessionFlags.HandlesMediaButtons |
                              MediaSessionFlags.HandlesTransportControls);

            Context context       = ApplicationContext;
            var     intent        = new Intent(context, typeof(MainActivity));
            var     pendingIntent = PendingIntent.GetActivity(context, 99, intent, PendingIntentFlags.UpdateCurrent);

            _session.SetSessionActivity(pendingIntent);

            var extraBundle = new Bundle();

            extraBundle.PutBoolean("com.google.android.gms.car.media.ALWAYS_RESERVE_SPACE_FOR.ACTION_QUEUE", true);
            extraBundle.PutBoolean("com.google.android.gms.car.media.ALWAYS_RESERVE_SPACE_FOR.ACTION_SKIP_TO_PREVIOUS", true);
            extraBundle.PutBoolean("com.google.android.gms.car.media.ALWAYS_RESERVE_SPACE_FOR.ACTION_SKIP_TO_NEXT", true);
            extraBundle.PutBoolean("com.google.android.gms.car.media.ALWAYS_RESERVE_SPACE_FOR.ACTION_PLAY_PAUSE", true);
            _session.SetExtras(extraBundle);
            UpdatePlaybackState(null);
        }
예제 #2
0
        public MusicPlayer(MusicService service, MusicProvider musicProvider)
        {
            MusicPlayerState = PlaybackStateCode.None;
            _audioFocusState = AudioFocusState.NoFocusAndNoHide;
            _musicService    = service;
            _musicProvider   = musicProvider;
            _audioManager    = (AudioManager)service.GetSystemService(Context.AudioService);
            _wifiLock        = ((WifiManager)service.GetSystemService(Context.WifiService))
                               .CreateWifiLock(WifiMode.Full, "mywifilock");
            if (_mediaPlayer == null)
            {
                _mediaPlayer = new MediaPlayer();

                _mediaPlayer.SetWakeMode(_musicService.ApplicationContext,
                                         Android.OS.WakeLockFlags.Partial);
                _mediaPlayer.SetOnPreparedListener(this);
                _mediaPlayer.SetOnCompletionListener(this);
                _mediaPlayer.SetOnErrorListener(this);
                _mediaPlayer.SetOnSeekCompleteListener(this);
            }
        }