Exemplo n.º 1
0
        public static bool TryGenerateVideoThumbnail(string localFile, CGSize size, out UIImage image)
        {
            image = null;
            try {
                const float secondToGet = 1.0f;

                using (var player = new MPMoviePlayerController(NSUrl.FromFilename(localFile))) {
                    image = player.ThumbnailImageAt(
                        secondToGet,
                        MPMovieTimeOption.NearestKeyFrame
                        );

                    image = UIImageExtensions.ResizeAndDispose(image,
                                                               size,
                                                               ResizeMethod.AspectFill,
                                                               ResizeAlignment.CenterCenter
                                                               );
                    player.Stop();
                }
            } catch {
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public static void ShowVideoUrlMp4(this UIView view, string pathVideo)
        {
            var moviePlayer = new MPMoviePlayerController
            {
                ContentUrl     = new NSUrl(pathVideo),
                ShouldAutoplay = false,
                ControlStyle   = MPMovieControlStyle.Embedded
            };


            moviePlayer.View.Frame = view.Frame;
            moviePlayer.PrepareToPlay();

            moviePlayer.Play();
            moviePlayer.SetFullscreen(true, true);


            MPMoviePlayerController.Notifications.ObserveDidExitFullscreen((sender, e) =>
            {
                moviePlayer.Stop();
                moviePlayer.View.RemoveFromSuperview();
                moviePlayer.Dispose();
                moviePlayer = null;
                GC.Collect();
            });

            view.AddSubview(moviePlayer.View);
        }
Exemplo n.º 3
0
        public async Task <Stream> GetThumbnailAsync(CancellationToken ct, ThumbnailMode mode)
        {
            var stream = await UIThread.Current.Run(async ict =>
            {
                try
                {
                    var fileUrl = NSUrl.FromFilename(this.Path);
                    var movie   = new MPMoviePlayerController(fileUrl);

                    movie.ShouldAutoplay = false;
                    movie.Stop();

                    var image = movie.ThumbnailImageAt(1.0, MPMovieTimeOption.Exact);

                    movie.SafeDispose();

                    return(image.AsPNG().AsStream());
                }

                catch (Exception e)
                {
                    this.Log().Error("The thumbnail could not retrieved.", e);
                    return(null);
                }
            }, ct);

            return(stream);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Stops the movie player
        /// </summary>
        /// <param name="notification">Notification.</param>
        public void VideoFinished(NSNotification notification)
        {
            //firing twice???
            Debug.WriteLine("video finished or user hit done!");

            MoviePlayer.SetFullscreen(false, false);
            MoviePlayer.Stop();
        }
 public void Stop()
 {
     if (_isPlaying)
     {
         _moviePlayer.Stop();
         _isPlaying = false;
     }
 }
Exemplo n.º 6
0
        protected override void Dispose(bool disposing)
        {
            // Dispose all components
            _controller?.Stop();
            _controller?.Dispose();
            _controller = null;

            base.Dispose(disposing);
        }
Exemplo n.º 7
0
        public override bool Stop()
        {
            if (playerController != null && this.State != MediaState.Stopped)
            {
                // Stop Playing.
                playerController.Stop();
                playerController  = null;
                this.CurrentMedia = null;
                this.State        = MediaState.Stopped;
            }

            return(true);
        }
Exemplo n.º 8
0
        public void DisposeItem()
        {
            if (playerItemReachEndNotitication != null)
            {
                NSNotificationCenter.DefaultCenter.RemoveObserver(playerItemReachEndNotitication);
                playerItemReachEndNotitication = null;
            }

            if (movieController != null)
            {
                movieController.Stop();
                movieController.Dispose();
            }
        }
Exemplo n.º 9
0
 public void Stop()
 {
     moviePlayer.Stop();
 }
Exemplo n.º 10
0
		public void BtnPlay_TouchUpInside(object sender,EventArgs e)
		{
			moviePlayer = new MPMoviePlayerController (NSUrl.FromFilename ("VID_20150904_123931.mp4"));
			moviePlayer.View.Frame = new CoreGraphics.CGRect (50, 50, 500, 700);
			this.View.AddSubview (moviePlayer.View);
			UIButton btnp = new UIButton (UIButtonType.System);
			btnp.Frame = new CoreGraphics.CGRect (580, 340, 90, 30);
			btnp.SetTitle ("Play", UIControlState.Normal);
			btnp.TouchUpInside += (send, ev) => {
				moviePlayer.Play ();
			};
			UIButton btnstop = new UIButton (UIButtonType.System);
			btnstop.Frame = new CoreGraphics.CGRect (680, 340, 90, 30);
			btnstop.SetTitle ("Stop", UIControlState.Normal);
			btnstop.TouchUpInside += (send, ev) => {
				moviePlayer.Stop ();
			};
			this.View.AddSubviews (btnp, btnstop);
		}