Ejemplo n.º 1
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();
                }
            };
        }
        public MediaBrowsesFragment(string mediaId)
        {
            _subscriptionCallback = new SubscriptionCallback();
            _connectionCallback   = new ConnectionCallback();
            var args = new Bundle();

            args.PutString(ArgMediaId, mediaId);
            this.Arguments = args;
        }