protected internal void UpdateFrame(MyVideoPlayer source) { UIApplication.SharedApplication.InvokeOnMainThread (() => { this._UsingFullWidth = false; this._UsingFullHeight = false; var screenRect = UIScreen.MainScreen.Bounds; var w = screenRect.Size.Width; var h = screenRect.Size.Height; // update frame var f = this.Frame; if (source.ContentWidth <= 0) { f.Width = w; this._UsingFullWidth = true; } else { f.Width = Convert.ToSingle (source.ContentWidth); } if (source.ContentHeight <= 0) { f.Height = h; this._UsingFullHeight = true; } else { f.Height = Convert.ToSingle (source.ContentHeight); } this.Frame = f; this.SetNeedsDisplay (); }); }
public VideoPlayerView() { this._VideoPlayer = new MyVideoPlayer(); this.HorizontalOptions = LayoutOptions.FillAndExpand; this.VerticalOptions = LayoutOptions.FillAndExpand; this.Content = this._VideoPlayer; }
public MyPlayerView (MyVideoPlayer Parent) { this.BackgroundColor = UIColor.Clear; this._MoviePlayer = new MyMPMoviePlayerController (Parent); // add to subview this.AddSubview (this._MoviePlayer.View); }
public MyMPMoviePlayerController (MyVideoPlayer Parent) { this.ParentElement = Parent; NSNotificationCenter.DefaultCenter.AddObserver (this, new MonoTouch.ObjCRuntime.Selector("LoadChangedCallback:"), MPMoviePlayerController.LoadStateDidChangeNotification, null ); this._Token = new CancellationTokenSource (); Task.Run (async() => { while(true && this._Token.Token.IsCancellationRequested == false) { await Task.Delay(TimeSpan.FromMilliseconds(200), this._Token.Token); var t = this.CurrentPlaybackTime; var d = this.PlayableDuration; // is there a better way to calculate the end of video??? if (this.PlayableDuration > 1.000 && (Math.Abs(t - d) <= 0.0001 * double.Epsilon)) { this.ParentElement.State = VideoSamples.Library.VideoState.ENDED; this.ParentElement.Info = new VideoData { State = VideoSamples.Library.VideoState.ENDED, At = t, Duration = d }; this._EndOfVideo = true; } else { this._EndOfVideo = false; if (this.PlaybackState == MPMoviePlaybackState.Paused) { this.ParentElement.State = VideoSamples.Library.VideoState.PAUSE; } else if (this.PlaybackState == MPMoviePlaybackState.Stopped) { this.ParentElement.State = VideoSamples.Library.VideoState.STOP; } else if (this.PlaybackState == MPMoviePlaybackState.Playing) { this.ParentElement.State = VideoSamples.Library.VideoState.PLAY; } if (this.PlayableDuration > 1.000) { this.ParentElement.Info = new VideoData { State = this.ParentElement.State, At = (double.IsNaN(t) ? -1 : t), Duration = d }; } } } }, this._Token.Token); }