コード例 #1
0
        public void Initialize(Context context)
        {
            mMessageReceiver = new MusicControlsBroadcastReceiver(this);
            RegisterBroadcaster(context, mMessageReceiver);

            mediaSessionCompat = new MediaSessionCompat(context, "music-controls-media-session", null, mediaButtonPendingIntent);
            mediaSessionCompat.SetFlags(MediaSessionCompat.FlagHandlesMediaButtons | MediaSessionCompat.FlagHandlesTransportControls);

            SetMediaPlaybackState((int)PlaybackStateCompat.StatePaused);

            mediaSessionCompat.Active = true;
            mediaSessionCompat.SetCallback(mMediaSessionCallback);

            try
            {
                mAudioManager = (AudioManager)context.GetSystemService(Context.AudioService);
                var headsetIntent = new Intent(musicControlsButton);
                mediaButtonPendingIntent = PendingIntent.GetBroadcast(context, 0, headsetIntent, PendingIntentFlags.UpdateCurrent);
                RegisterMediaButtonEvent();

                //MediaButtonReceiver.HandleIntent(mediaSessionCompat, headsetIntent);
                //BroadcastReceiver.
            }
            catch (Exception exc)
            {
            }
        }
コード例 #2
0
        private void RegisterBroadcaster(Context context, MusicControlsBroadcastReceiver mMessageReceiver)
        {
            context.RegisterReceiver(mMessageReceiver, new IntentFilter("music-controls-previous"));
            context.RegisterReceiver(mMessageReceiver, new IntentFilter("music-controls-pause"));
            context.RegisterReceiver(mMessageReceiver, new IntentFilter("music-controls-play"));
            context.RegisterReceiver(mMessageReceiver, new IntentFilter("music-controls-next"));
            context.RegisterReceiver(mMessageReceiver, new IntentFilter(musicControlsButton));
            context.RegisterReceiver(mMessageReceiver, new IntentFilter("music-controls-destroy"));
            context.RegisterReceiver(mMessageReceiver, new IntentFilter(Intent.ActionHeadsetPlug));
            context.RegisterReceiver(mMessageReceiver, new IntentFilter(BluetoothHeadset.ActionAudioStateChanged));
            context.RegisterReceiver(mMessageReceiver, new IntentFilter(BluetoothHeadset.ActionConnectionStateChanged));
            context.RegisterReceiver(mMessageReceiver, new IntentFilter(BluetoothHeadset.ActionVendorSpecificHeadsetEvent));
            context.RegisterReceiver(mMessageReceiver, new IntentFilter(BluetoothHeadset.ExtraVendorSpecificHeadsetEventCmd));
            context.RegisterReceiver(mMessageReceiver, new IntentFilter(BluetoothHeadset.ExtraVendorSpecificHeadsetEventArgs));
            context.RegisterReceiver(mMessageReceiver, new IntentFilter(BluetoothHeadset.ExtraVendorSpecificHeadsetEventCmdType));
            context.RegisterReceiver(mMessageReceiver, new IntentFilter(BluetoothHeadset.VendorResultCodeCommandAndroid));
            context.RegisterReceiver(mMessageReceiver, new IntentFilter(BluetoothHeadset.VendorSpecificHeadsetEventCompanyIdCategory));
            context.RegisterReceiver(mMessageReceiver, new IntentFilter(Intent.ActionMediaButton));

            //var l = LocalBroadcastManager.GetInstance(context);
            //l.RegisterReceiver(mMessageReceiver, new IntentFilter("music-controls-previous"));
            //l.RegisterReceiver(mMessageReceiver, new IntentFilter("music-controls-pause"));
            //l.RegisterReceiver(mMessageReceiver, new IntentFilter("music-controls-play"));
            //l.RegisterReceiver(mMessageReceiver, new IntentFilter("music-controls-next"));
            //l.RegisterReceiver(mMessageReceiver, new IntentFilter("music-controls-media-button"));
            //l.RegisterReceiver(mMessageReceiver, new IntentFilter("music-controls-destroy"));
            //l.RegisterReceiver(mMessageReceiver, new IntentFilter(Intent.ActionHeadsetPlug));
            //l.RegisterReceiver(mMessageReceiver, new IntentFilter(BluetoothHeadset.ActionAudioStateChanged));
            //l.RegisterReceiver(mMessageReceiver, new IntentFilter(BluetoothHeadset.ActionConnectionStateChanged));
            //l.RegisterReceiver(mMessageReceiver, new IntentFilter(BluetoothHeadset.ActionVendorSpecificHeadsetEvent));
            //l.RegisterReceiver(mMessageReceiver, new IntentFilter(BluetoothHeadset.ExtraVendorSpecificHeadsetEventCmd));
            //l.RegisterReceiver(mMessageReceiver, new IntentFilter(BluetoothHeadset.ExtraVendorSpecificHeadsetEventArgs));
            //l.RegisterReceiver(mMessageReceiver, new IntentFilter(BluetoothHeadset.ExtraVendorSpecificHeadsetEventCmdType));
            //l.RegisterReceiver(mMessageReceiver, new IntentFilter(BluetoothHeadset.VendorResultCodeCommandAndroid));
            //l.RegisterReceiver(mMessageReceiver, new IntentFilter(BluetoothHeadset.VendorSpecificHeadsetEventCompanyIdCategory));
        }