public override void OnListenerConnected()
        {
            activeMediaSessionsListener = new ActiveMediaSessionsListener();
            //RemoteController Lollipop and Beyond Implementation
            mediaSessionManager = (MediaSessionManager)GetSystemService(MediaSessionService);

            //Listener para Sesiones
            using (var h = new Handler(Looper.MainLooper)) //Using UI Thread because seems to crash in some devices.
                h.Post(() =>
                {
                    try
                    {
                        mediaSessionManager.AddOnActiveSessionsChangedListener(activeMediaSessionsListener, new ComponentName(this, Java.Lang.Class.FromType(typeof(Catcher))));
                        Log.Info("LiveDisplay", "Added Media Sess. Changed Listener");
                    }
                    catch
                    {
                        Log.Info("LiveDisplay", "Failed to register Media Session Callback");
                    }
                });

            SubscribeToEvents();
            RegisterReceivers();
            //This is for blocking Headsup notifications in Android Marshmallow and on, it does not work though LOL, stupid Android.
            //NotificationManager notificationManager = GetSystemService(NotificationService) as NotificationManager;
            //notificationManager.NotificationPolicy = new NotificationManager.Policy(NotificationPriorityCategory.Alarms | NotificationPriorityCategory.Calls | NotificationPriorityCategory.Events | NotificationPriorityCategory.Media | NotificationPriorityCategory.Messages | NotificationPriorityCategory.Reminders | NotificationPriorityCategory.RepeatCallers | NotificationPriorityCategory.System | NotificationPriorityCategory.RepeatCallers, NotificationPrioritySenders.Starred, NotificationPrioritySenders.Starred);
            //notificationManager.SetInterruptionFilter(InterruptionFilter.None);
            RetrieveNotificationFromStatusBar();
        }
        private void RetrieveSessions()
        {
            mediaSessionManager = (MediaSessionManager)ApplicationContext.GetSystemService(MediaSessionService);

            var componentName  = new ComponentName(this, Java.Lang.Class.FromType(typeof(NotificationListener)));
            var activeSessions = mediaSessionManager.GetActiveSessions(componentName);
        }
Example #3
0
 public AudioPlayerBase(MediaSessionManager sessionManager)
 {
     _sessionManager              = sessionManager;
     applicationContext           = Application.Context;
     mediaPlayerServiceIntent     = GetMediaServiceIntent();
     mediaPlayerServiceConnection = new MediaServiceConnection <TService>(this);
     applicationContext.BindService(mediaPlayerServiceIntent, mediaPlayerServiceConnection, Bind.AutoCreate);
     _sessionManager.OnStatusChanged += (sender, i) => Status = GetStatusByCompatValue(i);
     StatusChanged += (sender, args) => OnPlayingHandler(args);
 }
Example #4
0
        public PlaybackService(
            WebApiManager webApiManager,
            WebPlaybackSdkManager webPlaybackSdkManager,
            MediaSessionManager mediaSessionManager,
            AuthorizationService spotifyServiceAuth,
            SpotifyServiceConfiguration spotifyServiceConfiguration)
        {
            dispatcher   = webApiManager;
            player       = webPlaybackSdkManager;
            mediaSession = mediaSessionManager;
            auth         = spotifyServiceAuth;
            config       = spotifyServiceConfiguration;

            PlaybackChanged       += OnDevicePotentiallyChanged;
            PlaybackChanged       += mediaSession.SetMetadata;
            auth.AuthStateChanged += OnReInitializationPotenitallyNeeded;

            playbackContextPollingTimer = new(
                callback : async _ => { if (await auth.IsUserLoggedIn())
                                        {
                                            await FirePlaybackContextChanged(await GetPlayback());
                                        }
                },
                state : null,
                dueTime : 0,
                period : 1000);

            playbackUpdateTimer = new(
                callback : async _ => { if (await auth.IsUserLoggedIn())
                                        {
                                            PlaybackDisplayUpdate?.Invoke(GetProgressMs());
                                        }
                },
                state : null,
                dueTime : 0,
                period : 33);

            int playbackKeepAliveTimerPeriod = Convert.ToInt32(TimeSpan.FromMinutes(1).TotalMilliseconds);

            playbackKeepAliveTimer = new(
                callback : async _ => { if (await auth.IsUserLoggedIn())
                                        {
                                            await KeepPlaybackAlive();
                                        }
                },
                state : null,
                dueTime : playbackKeepAliveTimerPeriod,
                period : playbackKeepAliveTimerPeriod);
        }
Example #5
0
        public override void OnListenerConnected()
        {
            activeMediaSessionsListener = new ActiveMediaSessionsListener();
            //RemoteController Lollipop and Beyond Implementation
            mediaSessionManager = (MediaSessionManager)GetSystemService(MediaSessionService);

            //Listener para Sesiones
            using (var h = new Handler(Looper.MainLooper)) //Using UI Thread because seems to crash in some devices.
                h.Post(() =>
                {
                    mediaSessionManager.AddOnActiveSessionsChangedListener(activeMediaSessionsListener, new ComponentName(this, Java.Lang.Class.FromType(typeof(Catcher))));
                    Log.Info("LiveDisplay", "Added Media Sess. Changed Listener");
                });

            SubscribeToEvents();
            RegisterReceivers();
            RetrieveNotificationFromStatusBar();
        }
Example #6
0
 public ExoPlayerAudioImplementation(MediaSessionManager sessionManager) : base(sessionManager)
 {
 }
Example #7
0
 internal void SetMediaSession(MediaSessionManager sessionManager)
 {
     SessionManager = sessionManager;
     SessionManager.RemoteComponentName = new ComponentName(PackageName, new RemoteControlBroadcastReceiver().ComponentName);
 }
 public AudioPlayerBroadcastReceiver(MediaSessionManager manager)
 {
     _manager = manager;
 }