public async Task PlayPrevious_QueueHasPrevious_PlaysPrevious()
        {
            _mediaManagerMock
            .Setup(mediaManager => mediaManager.PlayPrevious())
            .Returns(Task.FromResult(0));

            MediaQueue = GetMediaQueue(hasPrevious: true);

            var playbackController = new PlaybackController(MediaManager);

            await playbackController.PlayPrevious();

            _mediaManagerMock
            .Verify(mediaManager => mediaManager.PlayPrevious(), Times.Once);
        }
Esempio n. 2
0
        public void BindEvents()
        {
            PlaybackController.MediaItemChanged   += PlaybackController_MediaItemChanged;
            PlaybackController.MediaItemFinished  += PlaybackController_MediaItemFinished;
            PlaybackController.StateChanged       += PlaybackController_StateChanged;
            MediaPlayer.MediaPlayer.BeforePlaying += MediaPlayer_BeforePlaying;
            element.Stop            = () => PlaybackController.Stop();
            element.Play            = () => PlaybackController.Play();
            element.Abort           = () => aborted = true;
            element.Reset           = () => aborted = false;
            element.PlayQueueItem   = PlayQueueItem;
            element.GetCurrentMedia = () => MediaPlayer.MediaQueue.Current != null ? new Realm.Of.Y.Manager.Models.Container.MediaItem(MediaPlayer.MediaQueue.Current.MediaUri)
            {
                Title = MediaPlayer.MediaQueue.Current.Title
            } : null;
            seeker.ProgressChanged    += Seeker_ProgressChanged;
            youtube_button_prev.Click += (sender, e) =>
            {
                PlaybackController.PlayPrevious();
                element?.OnPrev?.Invoke();
            };

            youtube_button_next.Click += (sender, e) =>
            {
                PlaybackController.PlayNext();
                element?.OnNext?.Invoke();
            };

            fullscreen_button.Click += (s, e) => { Fullscreen_button_Click(null, null); };
            btnPlay.Click           += TogglePlay;
            element.OnPlayVideo      = (items) => PlayVideo(items);
            element.SetFullScrean    = (n) =>
            {
                fullScrean = !n;
                Fullscreen_button_Click(null, null);
            };
        }
        //public MediaPlayerViewCtr(string mediaUrl)
        //{
        //	MediaUrl = mediaUrl;
        //	_viewModel = new MediaPlayerViewModel();
        //	_viewModel.Init(mediaUrl);
        //}

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            _viewModel.PropertyChanged += (sender, args) =>
            {
                var propertyName = args.PropertyName;
                var allChanged   = propertyName == null;

                Func <string, bool> hasChanged = property => allChanged || propertyName == property;

                InvokeOnMainThread(() =>
                {
                    if (hasChanged(nameof(MediaPlayerViewModel.PlayingText)))
                    {
                        QueueLabel.Text = _viewModel.PlayingText;
                    }

                    if (hasChanged(nameof(MediaPlayerViewModel.Cover)))
                    {
                        TrackCoverImageView.Image = (UIImage)_viewModel.Cover;
                    }

                    if (hasChanged(nameof(MediaPlayerViewModel.CurrentTrack)))
                    {
                        TitleLabel.Text    = _viewModel.CurrentTrack.Metadata.Title;
                        SubtitleLabel.Text = _viewModel.CurrentTrack.Metadata.Artist;
                    }

                    if (hasChanged(nameof(MediaPlayerViewModel.IsPlaying)))
                    {
                        PlayPauseButton.Selected = _viewModel.IsPlaying;
                    }

                    if (hasChanged(nameof(MediaPlayerViewModel.Duration)))
                    {
                        PlayingProgressSlider.MaxValue  = _viewModel.Duration;
                        BufferedProgressSlider.MaxValue = _viewModel.Duration;

                        var duration = TimeSpan.FromSeconds(_viewModel.Duration);

                        TimeTotalLabel.Text = GetTimeString(duration);
                    }

                    if (hasChanged(nameof(MediaPlayerViewModel.Position)))
                    {
                        PlayingProgressSlider.Value = _viewModel.Position;
                        TimePlayedLabel.Text        = GetTimeString(TimeSpan.FromSeconds(_viewModel.Position));
                    }

                    if (hasChanged(nameof(MediaPlayerViewModel.Downloaded)))
                    {
                        BufferedProgressSlider.Value = _viewModel.Downloaded;
                    }
                });
            };

            MediaPlayer.PlayingChanged += (sender, args) =>
            {
                if (!_viewModel.IsSeeking)
                {
                    InvokeOnMainThread(() =>
                    {
                        TimePlayedLabel.Text = GetTimeString(args.Position);
                    });
                }
            };

            MediaPlayer.MediaQueue.PropertyChanged += (sender, e) =>
            {
                InvokeOnMainThread(() =>
                {
                    var propertyName = e.PropertyName;
                    var allChanged   = propertyName == null;

                    Func <string, bool> hasChanged = property => allChanged || propertyName == property;

                    if (hasChanged(nameof(MediaPlayer.MediaQueue.IsShuffled)))
                    {
                        ShuffleButton.Selected = MediaPlayer.MediaQueue.IsShuffled;
                    }

                    if (hasChanged(nameof(MediaPlayer.MediaQueue.Repeat)))
                    {
                        var iconPrefix = "icon_repeat_";
                        var extension  = ".png";

                        string iconState;

                        switch (MediaPlayer.MediaQueue.Repeat)
                        {
                        case RepeatType.None:
                            iconState = "static";
                            break;

                        case RepeatType.RepeatAll:
                            iconState = "active";
                            break;

                        case RepeatType.RepeatOne:
                            iconState = "one_active";
                            break;

                        default:
                            iconState = "static";
                            break;
                        }

                        var imageUrl = iconPrefix + iconState + extension;

                        var image = new UIImage(imageUrl);
                        RepeatButton.SetImage(image, UIControlState.Normal);
                    }
                });
            };

            PlayingProgressSlider.TouchDown += (sender, e) =>
            {
                _viewModel.IsSeeking = true;
            };

            PlayingProgressSlider.TouchUpInside += (sender, e) =>
            {
                _viewModel.IsSeeking = false;
            };

            PlayingProgressSlider.TouchUpOutside += (sender, e) =>
            {
                _viewModel.IsSeeking = false;
            };

            PlayingProgressSlider.ValueChanged += (sender, e) =>
            {
                _viewModel.IsSeeking = true;
                _viewModel.Position  = (int)PlayingProgressSlider.Value;
            };

            PlayingProgressSlider.Continuous = true;

            PlayPauseButton.TouchUpInside += async(sender, e) =>
            {
                await PlaybackController.PlayPause();

                PlayPauseButton.Selected = _viewModel.IsPlaying;
            };

            NextButton.TouchUpInside += async(sender, e) =>
            {
                await PlaybackController.PlayNext();
            };

            PreviousButton.TouchUpInside += async(sender, e) =>
            {
                await PlaybackController.PlayPrevious();
            };

            ShuffleButton.TouchUpInside += (sender, args) =>
            {
                PlaybackController.ToggleShuffle();
            };

            RepeatButton.TouchUpInside += (sender, e) =>
            {
                PlaybackController.ToggleRepeat();
            };

            _viewModel.Init();

            var sampleFilePath = NSBundle.MainBundle.PathForResource("local-sample", "mp4");

            _viewModel.Queue.Add(new MediaFile
            {
                Type         = MediaFileType.Video,
                Url          = sampleFilePath,
                Availability = ResourceAvailability.Local
            });
        }