public MediaNotificationManager(MusicService serv)
        {
            service = serv;
            UpdateSessionToken();

            notificationColor = ResourceHelper.GetThemeColor(service,
                Android.Resource.Attribute.ColorPrimary, Color.DarkGray);

            notificationManager = (NotificationManager) service
                .GetSystemService(Context.NotificationService);

            string 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(ActionPrev).SetPackage(pkg), PendingIntentFlags.CancelCurrent);
            nextIntent = PendingIntent.GetBroadcast(service, RequestCode,
                new Intent(ActionNext).SetPackage(pkg), PendingIntentFlags.CancelCurrent);

            notificationManager.CancelAll ();

            mCb.OnPlaybackStateChangedImpl = (state) => {
                playbackState = state;
                LogHelper.Debug (Tag, "Received new playback state", state);
                if (state != null && (state.State == PlaybackStateCode.Stopped ||
                    state.State == PlaybackStateCode.None)) {
                    StopNotification ();
                } else {
                    Notification notification = CreateNotification ();
                    if (notification != null) {
                        notificationManager.Notify (NotificationId, notification);
                    }
                }
            };

            mCb.OnMetadataChangedImpl = (meta) => {
                metadata = meta;
                LogHelper.Debug (Tag, "Received new metadata ", metadata);
                Notification notification = CreateNotification ();
                if (notification != null) {
                    notificationManager.Notify (NotificationId, notification);
                }
            };

            mCb.OnSessionDestroyedImpl = () => {
                LogHelper.Debug (Tag, "Session was destroyed, resetting to the new session token");
                UpdateSessionToken ();
            };
        }
Пример #2
0
		public Playback(MusicService service, MusicProvider musicProvider) {
			this.service = service;
			this.musicProvider = musicProvider;
			audioManager = (AudioManager) service.GetSystemService(Context.AudioService);
			wifiLock = ((WifiManager) service.GetSystemService(Context.WifiService))
				.CreateWifiLock(WifiMode.Full, "sample_lock");
			mAudioNoisyReceiver.OnReceiveImpl = (context, intent) => {
				if (AudioManager.ActionAudioBecomingNoisy == intent.Action) {
					LogHelper.Debug(Tag, "Headphones disconnected.");
					if (IsPlaying) {
						var i = new Intent(context, typeof(MusicService));
						i.SetAction(MusicService.ActionCmd);
						i.PutExtra(MusicService.CmdName, MusicService.CmdPause);
						service.StartService(i);
					}
				}
			};
		}
Пример #3
0
 public Playback(MusicService service, MusicProvider musicProvider)
 {
     this.service       = service;
     this.musicProvider = musicProvider;
     audioManager       = (AudioManager)service.GetSystemService(Context.AudioService);
     wifiLock           = ((WifiManager)service.GetSystemService(Context.WifiService))
                          .CreateWifiLock(WifiMode.Full, "sample_lock");
     mAudioNoisyReceiver.OnReceiveImpl = (context, intent) => {
         if (AudioManager.ActionAudioBecomingNoisy == intent.Action)
         {
             LogHelper.Debug(Tag, "Headphones disconnected.");
             if (IsPlaying)
             {
                 var i = new Intent(context, typeof(MusicService));
                 i.SetAction(MusicService.ActionCmd);
                 i.PutExtra(MusicService.CmdName, MusicService.CmdPause);
                 service.StartService(i);
             }
         }
     };
 }
Пример #4
0
 public DelayedStopHandler(MusicService service)
 {
     weakReference = new WeakReference <MusicService> (service);
 }
Пример #5
0
			public DelayedStopHandler (MusicService service)
			{
				weakReference = new WeakReference<MusicService> (service);
			}