Пример #1
0
        public MediaNotificationManager(MusicService service)
        {
            callback.Parent = this;
            Service         = service;
            UpdateSessionToken();

            NotificationManager = NotificationManagerCompat.From(service);

            var pkg = service.PackageName;

            pauseIntent       = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionPause).SetPackage(pkg), PendingIntentFlags.CancelCurrent);
            playIntent        = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionPlay).SetPackage(pkg), PendingIntentFlags.CancelCurrent);
            previousIntent    = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionPrevious).SetPackage(pkg), PendingIntentFlags.CancelCurrent);
            nextIntent        = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionNext).SetPackage(pkg), PendingIntentFlags.CancelCurrent);
            stopCastingIntent = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionStopCasting).SetPackage(pkg), PendingIntentFlags.CancelCurrent);
            NotificationManager.CancelAll();
        }
Пример #2
0
        public override void OnCreate()
        {
            base.OnCreate();
            Shared = this;
            NativeAudioPlayer.NativeInit(this);
            PlaybackManager.Shared.Init();
            Session      = new MediaSessionCompat(this, "MusicService");
            SessionToken = Session.SessionToken;
            Session.SetCallback(sessionCallback = new MediaSessionCallback());
            Session.SetFlags(MediaSessionCompat.FlagHandlesMediaButtons |
                             MediaSessionCompat.FlagHandlesTransportControls);
            var context = ApplicationContext;
            var intent  = new Intent(ApplicationContext, typeof(NowPlayingActivity));
            var pi      = PendingIntent.GetActivity(context, 99, intent, PendingIntentFlags.UpdateCurrent);

            Session.SetSessionActivity(pi);

            sessionExtras = new Bundle();

            //		CarHelper.setSlotReservationFlags(mSessionExtras, true, true, true);
            //        WearHelper.setSlotReservationFlags(mSessionExtras, true, true);
            //        WearHelper.setUseBackgroundFromTheme(mSessionExtras, true);

            Session.SetExtras(sessionExtras);


            try
            {
                MediaNotificationManager = new MediaNotificationManager(this);
            }
            catch (Exception ex)
            {
                LogManager.Shared.Report(ex);
                throw ex;
            }

            //VideoCastManager.getInstance().addVideoCastConsumer(mCastConsumer);
            mediaRouter = Android.Support.V7.Media.MediaRouter.GetInstance(ApplicationContext);

            //registerCarConnectionReceiver();
            Managers.NotificationManager.Shared.PlaybackStateChanged += PlaybackStateChanged;
        }