예제 #1
0
        public void SwitchToPlayback(IPlayback playback, bool resumePlaying)
        {
            if (playback == null)
            {
                throw new ArgumentException("Playback cannot be null");
            }
            // suspend the current one.
            int oldState       = Playback.State;
            int pos            = Playback.CurrentStreamPosition;
            var currentMediaId = Playback.CurrentMediaId;

            Playback.Stop(false);
            Playback.Callback = this;
            Playback.CurrentStreamPosition = pos < 0 ? 0 : pos;
            Playback.CurrentMediaId        = currentMediaId;
            Playback.Start();
            // finally swap the instance
            Playback = playback;
            switch (oldState)
            {
            case PlaybackStateCompat.StateBuffering:
            case PlaybackStateCompat.StateConnecting:
            case PlaybackStateCompat.StatePaused:
                Playback.Pause();
                break;

            case PlaybackStateCompat.StatePlaying:
                MediaSessionCompat.QueueItem currentMusic = queueManager.CurrentMusic;
                if (resumePlaying && currentMusic != null)
                {
                    Playback.Play(currentMusic);
                }
                else if (!resumePlaying)
                {
                    Playback.Pause();
                }
                else
                {
                    Playback.Stop(true);
                }
                break;

            case PlaybackStateCompat.StateNone:
                break;

            default:
                LogHelper.Debug(Tag, "Default called. Old state is ", oldState);
                break;
            }
        }
예제 #2
0
 public static void Pause(int stream)
 {
     _Playback.Pause(stream);
 }
예제 #3
0
 public void Pause()
 {
     _playback?.Pause();
 }