Beispiel #1
0
 private static bool IsPlaybackStarted(MediaSession.Token token)
 {
     if (_currentToken.Equals(token) && _playbackstarted == true)
     {
         return(true);
     }
     return(false);
 }
        void UpdateSessionToken()
        {
            var freshToken = service.SessionToken;

            if (sessionToken == null || sessionToken != freshToken)
            {
                if (controller != null)
                {
                    controller.UnregisterCallback(mCb);
                }
                sessionToken      = freshToken;
                controller        = new MediaController(service, sessionToken);
                transportControls = controller.GetTransportControls();
                if (started)
                {
                    controller.RegisterCallback(mCb);
                }
            }
        }
Beispiel #3
0
 //if you don't pass any argument it'll effectively do nothing.
 public static bool StopPlayback(MediaSession.Token token = null)
 {
     if (_currentToken == token) //Making sure we are stopping the same one we started.
     {
         try
         {
             _currentMediaController.UnregisterCallback(instance);
             _playbackstarted    = false;
             _openNotificationId = null;
             return(true);
         }
         catch (Exception)
         {
             Log.Warn("LiveDisplay", "Failed MusicController#StopMediaCallback");
             _playbackstarted    = false;
             _openNotificationId = null;
             return(false);
         }
     }
     return(false);
 }
Beispiel #4
0
        /// <summary>
        /// Pass a MediaSession.Token to create one MediaController.
        ///
        /// </summary>
        /// <param name="mediaController"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static bool StartPlayback(MediaSession.Token token, string owningNotificationId)
        {
            if (instance == null)
            {
                if (token != null)
                {
                    _currentMediaController = new MediaController(Application.Context, token);
                    _currentToken           = token;
                }
                else
                {
                    throw new ArgumentException("Token can't be null!");
                }
                GetCurrentInstance(_currentMediaController, owningNotificationId);
                return(StartMediaPlayback());
            }
            else
            {
                if (IsPlaybackStarted(token) == false)
                {
                    StopPlayback(_currentToken); //the incoming token is different so I will stop the previous media callback before
                                                 //creating a new one.

                    _currentMediaController = new MediaController(Application.Context, token);
                    _currentToken           = token;
                    LoadMediaControllerData(_currentMediaController);
                    return(StartMediaPlayback());
                }
                else
                {
                    //The mediaplayback is already started for this session in particular.

                    if (_openNotificationId != owningNotificationId) //It means that the session is the same, but the notification owning this session changed.
                    {
                        _openNotificationId = owningNotificationId;  //Update the notification (taking its id) that way we can identify the notification that owns this media session.
                    }
                    return(false);
                }
            }
        }
 void UpdateSessionToken()
 {
     var freshToken = service.SessionToken;
     if (sessionToken == null || sessionToken != freshToken) {
         if (controller != null) {
             controller.UnregisterCallback (mCb);
         }
         sessionToken = freshToken;
         controller = new MediaController (service, sessionToken);
         transportControls = controller.GetTransportControls();
         if (started) {
             controller.RegisterCallback (mCb);
         }
     }
 }