QueueFragment()
        {
            connectionCallback.OnConnectedImpl = () => {
                LogHelper.Debug(Tag, "onConnected: session token ", mediaBrowser.SessionToken);

                if (mediaBrowser.SessionToken == null)
                {
                    throw new InvalidOperationException("No Session token");
                }

                mediaController = new Android.Media.Session.MediaController(Activity,
                                                                            mediaBrowser.SessionToken);
                transportControls = mediaController.GetTransportControls();
                mediaController.RegisterCallback(sessionCallback);

                Activity.MediaController = mediaController;
                playbackState            = mediaController.PlaybackState;

                var queue = (JavaList)mediaController.Queue;
                if (queue != null)
                {
                    queueAdapter.Clear();
                    queueAdapter.NotifyDataSetInvalidated();
                    queueAdapter.AddAll(queue.ToArray());
                    queueAdapter.NotifyDataSetChanged();
                }
                OnPlaybackStateChanged(playbackState);
            };

            connectionCallback.OnConnectionFailedImpl    = () => LogHelper.Debug(Tag, "onConnectionFailed");
            connectionCallback.OnConnectionSuspendedImpl = () => {
                LogHelper.Debug(Tag, "onConnectionSuspended");
                mediaController.UnregisterCallback(sessionCallback);
                transportControls        = null;
                mediaController          = null;
                Activity.MediaController = null;
            };

            sessionCallback.OnSessionDestroyedImpl     = () => LogHelper.Debug(Tag, "Session destroyed. Need to fetch a new Media Session");
            sessionCallback.OnPlaybackStateChangedImpl = state => {
                if (state == null)
                {
                    return;
                }
                LogHelper.Debug(Tag, "Received playback state change to state ", state.State);
                playbackState = state;
                OnPlaybackStateChanged(state);
            };

            sessionCallback.OnQueueChangedImpl = queue => {
                LogHelper.Debug(Tag, "onQueueChanged ", queue);
                if (queue != null)
                {
                    queueAdapter.Clear();
                    queueAdapter.NotifyDataSetInvalidated();
                    queueAdapter.AddAll(queue.ToArray());
                    queueAdapter.NotifyDataSetChanged();
                }
            };
        }
Exemple #2
0
        public MediaPlayerFragment()
        {
            _connectionCallback = new ConnectionCallback();
            _sessionCallback    = new SessionCallback();
            _connectionCallback.OnConnectedImpl = () =>
            {
                if (_mediaBrowser.SessionToken == null)
                {
                    throw new InvalidOperationException("No Session token");
                }

                _mediaController = new Android.Media.Session.MediaController(Activity,
                                                                             _mediaBrowser.SessionToken);
                _transportControls = _mediaController.GetTransportControls();
                _mediaController.RegisterCallback(_sessionCallback);

                Activity.MediaController = _mediaController;
                _playbackState           = _mediaController.PlaybackState;

                var queue = (JavaList)_mediaController.Queue;
                if (queue != null)
                {
                    _queueAdapter.Clear();
                    _queueAdapter.NotifyDataSetInvalidated();
                    _queueAdapter.AddAll(queue.ToArray());
                    _queueAdapter.NotifyDataSetChanged();
                }
                OnPlaybackStateChanged(_playbackState);
            };
            _connectionCallback.OnConnectionFailedImpl    = () => Logger.Debug("OnConnectionFailedImpl");
            _connectionCallback.OnConnectionSuspendedImpl = () =>
            {
                _mediaController.UnregisterCallback(_sessionCallback);
                _transportControls       = null;
                _mediaController         = null;
                Activity.MediaController = null;
            };
            _sessionCallback.OnSessionDestroyedImpl     = () => Logger.Debug("OnSessionDestroyedImpl");
            _sessionCallback.OnPlaybackStateChangedImpl = state =>
            {
                if (state == null)
                {
                    return;
                }
                _playbackState = state;
                OnPlaybackStateChanged(state);
            };
            _sessionCallback.OnQueueChangedImpl = queue =>
            {
                if (queue != null)
                {
                    _queueAdapter.Clear();
                    _queueAdapter.NotifyDataSetInvalidated();
                    _queueAdapter.AddAll(queue.ToArray());
                    _queueAdapter.NotifyDataSetChanged();
                }
            };
        }
		QueueFragment ()
		{
			connectionCallback.OnConnectedImpl = () => {
				LogHelper.Debug (Tag, "onConnected: session token ", mediaBrowser.SessionToken);

				if (mediaBrowser.SessionToken == null) {
					throw new InvalidOperationException ("No Session token");
				}

				mediaController = new Android.Media.Session.MediaController (Activity,
					mediaBrowser.SessionToken);
				transportControls = mediaController.GetTransportControls ();
				mediaController.RegisterCallback (sessionCallback);

				Activity.MediaController = mediaController;
				playbackState = mediaController.PlaybackState;

				var queue = (JavaList)mediaController.Queue;
				if (queue != null) {
					queueAdapter.Clear ();
					queueAdapter.NotifyDataSetInvalidated ();
					queueAdapter.AddAll(queue.ToArray());
					queueAdapter.NotifyDataSetChanged ();
				}
				OnPlaybackStateChanged (playbackState);
			};
			connectionCallback.OnConnectionFailedImpl = () => LogHelper.Debug (Tag, "onConnectionFailed");
			connectionCallback.OnConnectionSuspendedImpl = () => {
				LogHelper.Debug (Tag, "onConnectionSuspended");
				mediaController.UnregisterCallback (sessionCallback);
				transportControls = null;
				mediaController = null;
				Activity.MediaController = null;
			};
			sessionCallback.OnSessionDestroyedImpl = () => LogHelper.Debug (Tag, "Session destroyed. Need to fetch a new Media Session");
			sessionCallback.OnPlaybackStateChangedImpl = state => {
				if (state == null) {
					return;
				}
				LogHelper.Debug (Tag, "Received playback state change to state ", state.State);
				playbackState = state;
				OnPlaybackStateChanged (state);
			};
			sessionCallback.OnQueueChangedImpl = queue => {
				LogHelper.Debug (Tag, "onQueueChanged ", queue);
				if (queue != null) {
					queueAdapter.Clear ();
					queueAdapter.NotifyDataSetInvalidated ();
					queueAdapter.AddAll (queue.ToArray());
					queueAdapter.NotifyDataSetChanged ();
				}
			};
			buttonListener.OnClickImpl = v => {
				var state = playbackState == null ?
					PlaybackStateCode.None : playbackState.State;
				switch (v.Id) {
				case Resource.Id.play_pause:
					LogHelper.Debug (Tag, "Play button pressed, in state " + state);
					if (state == PlaybackStateCode.Paused ||
					    state == PlaybackStateCode.Stopped ||
					    state == PlaybackStateCode.None) {
						PlayMedia ();
					} else if (state == PlaybackStateCode.Playing) {
						PauseMedia ();
					}
					break;
				case Resource.Id.skip_previous:
					LogHelper.Debug (Tag, "Start button pressed, in state " + state);
					SkipToPrevious ();
					break;
				case Resource.Id.skip_next:
					SkipToNext ();
					break;
				}
			};
		}
		QueueFragment ()
		{
			connectionCallback.OnConnectedImpl = () => {
				LogHelper.Debug (Tag, "onConnected: session token ", mediaBrowser.SessionToken);

				if (mediaBrowser.SessionToken == null) {
					throw new InvalidOperationException ("No Session token");
				}

				mediaController = new Android.Media.Session.MediaController (Activity,
					mediaBrowser.SessionToken);
				transportControls = mediaController.GetTransportControls ();
				mediaController.RegisterCallback (sessionCallback);

				Activity.MediaController = mediaController;
				playbackState = mediaController.PlaybackState;

				var queue = (JavaList)mediaController.Queue;
				if (queue != null) {
					queueAdapter.Clear ();
					queueAdapter.NotifyDataSetInvalidated ();
					queueAdapter.AddAll(queue.ToArray());
					queueAdapter.NotifyDataSetChanged ();
				}
				OnPlaybackStateChanged (playbackState);
			};
			connectionCallback.OnConnectionFailedImpl = () => LogHelper.Debug (Tag, "onConnectionFailed");
			connectionCallback.OnConnectionSuspendedImpl = () => {
				LogHelper.Debug (Tag, "onConnectionSuspended");
				mediaController.UnregisterCallback (sessionCallback);
				transportControls = null;
				mediaController = null;
				Activity.MediaController = null;
			};
			sessionCallback.OnSessionDestroyedImpl = () => LogHelper.Debug (Tag, "Session destroyed. Need to fetch a new Media Session");
			sessionCallback.OnPlaybackStateChangedImpl = state => {
				if (state == null) {
					return;
				}
				LogHelper.Debug (Tag, "Received playback state change to state ", state.State);
				playbackState = state;
				OnPlaybackStateChanged (state);
			};
			sessionCallback.OnQueueChangedImpl = queue => {
				LogHelper.Debug (Tag, "onQueueChanged ", queue);
				if (queue != null) {
					queueAdapter.Clear ();
					queueAdapter.NotifyDataSetInvalidated ();
					queueAdapter.AddAll (queue.ToArray());
					queueAdapter.NotifyDataSetChanged ();
				}
			};
		}
Exemple #5
0
        QueueFragment()
        {
            connectionCallback.OnConnectedImpl = () => {
                LogHelper.Debug(Tag, "onConnected: session token ", mediaBrowser.SessionToken);

                if (mediaBrowser.SessionToken == null)
                {
                    throw new InvalidOperationException("No Session token");
                }

                mediaController = new Android.Media.Session.MediaController(Activity,
                                                                            mediaBrowser.SessionToken);
                transportControls = mediaController.GetTransportControls();
                mediaController.RegisterCallback(sessionCallback);

                Activity.MediaController = mediaController;
                playbackState            = mediaController.PlaybackState;

                var queue = (JavaList)mediaController.Queue;
                if (queue != null)
                {
                    queueAdapter.Clear();
                    queueAdapter.NotifyDataSetInvalidated();
                    queueAdapter.AddAll(queue.ToArray());
                    queueAdapter.NotifyDataSetChanged();
                }
                OnPlaybackStateChanged(playbackState);
            };
            connectionCallback.OnConnectionFailedImpl    = () => LogHelper.Debug(Tag, "onConnectionFailed");
            connectionCallback.OnConnectionSuspendedImpl = () => {
                LogHelper.Debug(Tag, "onConnectionSuspended");
                mediaController.UnregisterCallback(sessionCallback);
                transportControls        = null;
                mediaController          = null;
                Activity.MediaController = null;
            };
            sessionCallback.OnSessionDestroyedImpl     = () => LogHelper.Debug(Tag, "Session destroyed. Need to fetch a new Media Session");
            sessionCallback.OnPlaybackStateChangedImpl = state => {
                if (state == null)
                {
                    return;
                }
                LogHelper.Debug(Tag, "Received playback state change to state ", state.State);
                playbackState = state;
                OnPlaybackStateChanged(state);
            };
            sessionCallback.OnQueueChangedImpl = queue => {
                LogHelper.Debug(Tag, "onQueueChanged ", queue);
                if (queue != null)
                {
                    queueAdapter.Clear();
                    queueAdapter.NotifyDataSetInvalidated();
                    queueAdapter.AddAll(queue.ToArray());
                    queueAdapter.NotifyDataSetChanged();
                }
            };
            buttonListener.OnClickImpl = v => {
                var state = playbackState == null ?
                            PlaybackStateCode.None : playbackState.State;
                switch (v.Id)
                {
                case Resource.Id.play_pause:
                    LogHelper.Debug(Tag, "Play button pressed, in state " + state);
                    if (state == PlaybackStateCode.Paused ||
                        state == PlaybackStateCode.Stopped ||
                        state == PlaybackStateCode.None)
                    {
                        PlayMedia();
                    }
                    else if (state == PlaybackStateCode.Playing)
                    {
                        PauseMedia();
                    }
                    break;

                case Resource.Id.skip_previous:
                    LogHelper.Debug(Tag, "Start button pressed, in state " + state);
                    SkipToPrevious();
                    break;

                case Resource.Id.skip_next:
                    SkipToNext();
                    break;
                }
            };
        }