Esempio n. 1
0
        void UpdatePlaybackControls()
        {
            var playbackState = MusicPlayerManager.MusicPlayerController.PlaybackState;

            switch (playbackState)
            {
            case MPMusicPlaybackState.Stopped:
            case MPMusicPlaybackState.Paused:
            case MPMusicPlaybackState.Interrupted:
                BtnPlayPause.SetImage(UIImage.FromBundle("Play"), UIControlState.Normal);
                break;

            case MPMusicPlaybackState.Playing:
                BtnPlayPause.SetImage(UIImage.FromBundle("Pause"), UIControlState.Normal);
                break;

            default:
                break;
            }

            if (playbackState == MPMusicPlaybackState.Stopped)
            {
                BtnSkipToPrevious.Enabled = false;
                BtnPlayPause.Enabled      = false;
                BtnSkipToNext.Enabled     = false;
            }
            else
            {
                BtnSkipToPrevious.Enabled = true;
                BtnPlayPause.Enabled      = true;
                BtnSkipToNext.Enabled     = true;
            }

            UpdateCurrentItemMetadata();
        }
        public void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            // Play selected video from Playlist
            var video = videos[indexPath.Row];

            PlayerView.PlayVideoAt(indexPath.Row);

            BtnPlayPause.SetTitle("Play", UIControlState.Normal);
            DisableButton(BtnPlayPause);

            if (indexPath.Row == 0)
            {
                DisableButton(BtnPrevious);
            }
            else
            {
                EnableButton(BtnPrevious);
            }

            if (indexPath.Row == videos.Count - 1)
            {
                DisableButton(BtnNext);
            }
            else
            {
                EnableButton(BtnNext);
            }
        }
        void ReleaseDesignerOutlets()
        {
            if (BtnPlayPause != null)
            {
                BtnPlayPause.Dispose();
                BtnPlayPause = null;
            }

            if (BtnStop != null)
            {
                BtnStop.Dispose();
                BtnStop = null;
            }

            if (PlayerView != null)
            {
                PlayerView.Dispose();
                PlayerView = null;
            }

            if (TblVideos != null)
            {
                TblVideos.Dispose();
                TblVideos = null;
            }
        }
        // Player View Delegate

        // To know when the Player View is ready to reproduce videos.
        void PlayerView_BecameReady(object sender, EventArgs e)
        {
            Console.WriteLine($"Player is ready to reproduce videos");

            BtnPlayPause.Enabled = true;
            BtnPlayPause.SetTitleColor(YouTubeManager.YouTubeColor, UIControlState.Normal);
        }
        // To know when Player View changes the video state.
        void PlayerView_StateChanged(object sender, PlayerViewStateChangedEventArgs e)
        {
            Console.WriteLine($"Player changed state to {e.State}");

            if (e.State == PlayerState.Queued)
            {
                BtnPlayPause.SetTitle("Play Video", UIControlState.Normal);
                BtnPlayPause.Enabled = true;
                BtnPlayPause.SetTitleColor(YouTubeManager.YouTubeColor, UIControlState.Normal);
            }
        }
 // Play/Pause the current video in the YouTube Player.
 void BtnPlayPause_TouchUpInside(object sender, EventArgs e)
 {
     if (PlayerView.PlayerState == PlayerState.Playing)
     {
         PlayerView.PauseVideo();
         BtnPlayPause.SetTitle("Play", UIControlState.Normal);
     }
     else
     {
         PlayerView.PlayVideo();
         BtnPlayPause.SetTitle("Pause", UIControlState.Normal);
     }
 }
        // To know when Player View changes the video state.
        void PlayerView_StateChanged(object sender, PlayerViewStateChangedEventArgs e)
        {
            Console.WriteLine($"Player changed state to {e.State}");

            if (e.State == PlayerState.Queued)
            {
                BtnPlayPause.SetTitle("Play", UIControlState.Normal);
                EnableButton(BtnPlayPause);
            }

            if (e.State == PlayerState.Playing)
            {
                BtnPlayPause.SetTitle("Pause", UIControlState.Normal);
                EnableButton(BtnPlayPause);
            }
        }
        void ReleaseDesignerOutlets()
        {
            if (BtnPlayPause != null)
            {
                BtnPlayPause.Dispose();
                BtnPlayPause = null;
            }

            if (BtnSkipToNext != null)
            {
                BtnSkipToNext.Dispose();
                BtnSkipToNext = null;
            }

            if (BtnSkipToPrevious != null)
            {
                BtnSkipToPrevious.Dispose();
                BtnSkipToPrevious = null;
            }

            if (ImgCurrentArtwork != null)
            {
                ImgCurrentArtwork.Dispose();
                ImgCurrentArtwork = null;
            }

            if (LblCurrentAlbum != null)
            {
                LblCurrentAlbum.Dispose();
                LblCurrentAlbum = null;
            }

            if (LblCurrentArtist != null)
            {
                LblCurrentArtist.Dispose();
                LblCurrentArtist = null;
            }

            if (LblCurrentTitle != null)
            {
                LblCurrentTitle.Dispose();
                LblCurrentTitle = null;
            }
        }
        public void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            if (videos.Count == 0)
            {
                return;
            }

            BtnPlayPause.SetTitle("Play Video", UIControlState.Normal);
            BtnPlayPause.SetTitleColor(YouTubeManager.DisabledColor, UIControlState.Normal);
            BtnPlayPause.Enabled = false;

            var video = videos[indexPath.Row];

            if (firstLoad)
            {
                PlayerView.LoadVideoById(video.Id);
                firstLoad = false;
            }
            else
            {
                PlayerView.CueVideoById(video.Id, 0, PlaybackQuality.Auto);
            }
        }
 // Stop the current video in the YouTube Player.
 void BtnStop_TouchUpInside(object sender, EventArgs e)
 {
     PlayerView.StopVideo();
     BtnPlayPause.SetTitle("Play", UIControlState.Normal);
 }