public void OnPrepared(MediaPlayer mp)
        {
            if (Status == MediaPlayerStatus.Buffering)
            {
                VideoViewCanvas.Start();
            }

            Status = MediaPlayerStatus.Playing;
        }
        public void OnPrepared(MediaPlayer mp)
        {
            Console.WriteLine($"OnPrepared: {Status}");

            _mediaPlayer = mp;

            if (Status == MediaPlayerStatus.Buffering)
            {
                VideoViewCanvas.Start();
            }

            Status = MediaPlayerStatus.Playing;
        }
        public async Task Play(IMediaFile mediaFile = null)
        {
            if (!IsReadyRendering)
            {
                //Android ViewRenderer might not initialize Control yet
                return;
            }

            if (isPlayerReady == false)
            {
                //await Task.Delay(100);
                Init();
                isPlayerReady = true;
            }

            if (mediaFile == null || (mediaFile != null && string.IsNullOrEmpty(mediaFile.Url)))
            {
                return;
            }

            if (mediaFile != null && CurrentFile != mediaFile)
            {
                CurrentFile = mediaFile;
                currentUri  = Android.Net.Uri.Parse(mediaFile.Url);
                VideoViewCanvas.StopPlayback();
                //VideoViewCanvas.Suspend();
                Status = MediaPlayerStatus.Stopped;
            }

            if (Status == MediaPlayerStatus.Paused)
            {
                //We are simply paused so just continue
                VideoViewCanvas.SeekTo(lastPosition);
                VideoViewCanvas.Start();

                Status = MediaPlayerStatus.Playing;
                return;
            }

            try
            {
                Status = MediaPlayerStatus.Buffering;
                VideoViewCanvas.SetVideoURI(currentUri, RequestHeaders);
            }
            catch (System.Exception ex)
            {
                OnMediaFailed(new MediaFailedEventArgs(ex.Message, ex));
                Status = MediaPlayerStatus.Stopped;
            }
        }
示例#4
0
        public async Task Play(IMediaFile mediaFile = null)
        {
            if (VideoViewCanvas == null)
            {
                await Task.Delay(100);

                Init();
            }

            if (mediaFile != null)
            {
                CurrentFile = mediaFile;
                currentUri  = Android.Net.Uri.Parse(mediaFile.Url);
            }

            if (Status == MediaPlayerStatus.Paused)
            {
                Status = MediaPlayerStatus.Playing;
                //We are simply paused so just continue
                VideoViewCanvas.Resume();
                return;
            }

            try
            {
                Status = MediaPlayerStatus.Buffering;

                VideoViewCanvas.SetVideoURI(currentUri);
                VideoViewCanvas.Start();
                Status = MediaPlayerStatus.Playing;
            }
            catch (Exception ex)
            {
                MediaFailed?.Invoke(this, new MediaFailedEventArgs(ex.Message, ex));
                Status = MediaPlayerStatus.Stopped;
            }
        }