protected override void OnElementChanged(ElementChangedEventArgs <VideoView> e) { if (e.NewElement != null) { if (string.IsNullOrEmpty(Element.Source)) { throw new ArgumentException("Source is required."); } if (base.Control == null) { var view = new UIView(); SetNativeControl(view); if (Element.ShowControl) { if (Element.IsFromUrl) { if (movieController == null) { var url = NSUrl.FromString(Element.Source); movieController = new MPMoviePlayerController(); movieController.ShouldAutoplay = true; movieController.Fullscreen = true; movieController.ControlStyle = MPMovieControlStyle.Embedded; movieController.PrepareToPlay(); movieController.SourceType = MPMovieSourceType.Streaming; movieController.ContentUrl = url; view.Add(movieController.View); movieController.Play(); movieController.SetFullscreen(true, true); } } } else { if (playerItem == null) { asset = AVAsset.FromUrl(NSUrl.FromFilename(Element.Source)); playerItem = new AVPlayerItem(asset); // AVPlayerItem.DidPlayToEndTimeNotification; player = new AVPlayer(playerItem); player.ActionAtItemEnd = AVPlayerActionAtItemEnd.None; playerLayer = AVPlayerLayer.FromPlayer(player); view.Layer.AddSublayer(playerLayer); SetRepeat(); SetPlaying(); } } } } base.OnElementChanged(e); }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. moviePlayer = new MPMoviePlayerController(NSUrl.FromString("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")); // Use FromString() to play video directly from web. moviePlayer.View.Frame = new CGRect(0, 20, View.Frame.Size.Width, 180); // size of the video frame moviePlayer.ScalingMode = MPMovieScalingMode.AspectFit; // show the video relative to the video size dimensions moviePlayer.PrepareToPlay(); moviePlayer.Play(); View.Add(moviePlayer.View); // add the view after video starts playing to display it // UILabel label = new UILabel(new CGRect(0, 200, View.Frame.Size.Width, 50)); label.Text = "Tutorial"; label.Font.WithSize(36); View.Add(label.ViewForBaselineLayout); // UITextView textView = new UITextView(); textView.Editable = false; textView.ScrollEnabled = true; textView.UserInteractionEnabled = true; textView.ViewForBaselineLayout.Frame = new CGRect(0, 250, View.Frame.Size.Width, View.Frame.Size.Height * 3); textView.Text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. [shorten text for this post] "; // shorten text for this post View.Add(textView); }
public override void ViewDidLoad() { base.ViewDidLoad(); //Button Events playMovieButton.TouchUpInside += delegate { try{ //Set already instantiated MPMoviePlayerController to playback from Movies/file.m4v mp = new MPMoviePlayerController(NSUrl.FromFilename("Movies/file.m4v")); //enable AirPlay mp.AllowsAirPlay = true; //Add the MPMoviePlayerController View this.View.AddSubview(mp.View); //set the view to be full screen and show animated mp.SetFullscreen(true, true); //Disable the pinch-to-zoom gesture mp.ControlStyle = MPMovieControlStyle.Fullscreen; //MPMoviePlayer must be set to PrepareToPlay before playback mp.PrepareToPlay(); //Play Movie mp.Play(); } catch { Console.WriteLine("There was a problem playing back Video"); } }; }
public override void ViewDidLoad() { base.ViewDidLoad(); RefreshControl.ValueChanged += (sender, e) => Task.Run(async() => await Refresh()); CollectionView.AddSubview(RefreshControl); var deletate = new CustomFlowLayoutDelegate(); deletate.ItemClick += async(sender, e) => { var item = await Detail.GetVideo(ID, List[e.Index].Set, LanguageHelper.PrefLang); var picker = new UIPickerView(); var model = new QualityPickerViewModel(item); model.ItemClick += (s2, e2) => { View.WillRemoveSubview(picker); if (moviePlayer == null) { moviePlayer = new MPMoviePlayerController(); View.AddSubview(moviePlayer.View); moviePlayer.ShouldAutoplay = true; } moviePlayer.ContentUrl = NSUrl.FromString(item.ToDictionary().Values.ToArray()[e2.Index]); moviePlayer.SetFullscreen(true, false); moviePlayer.PrepareToPlay(); moviePlayer.Play(); }; View.AddSubview(picker); picker.Hidden = false; }; CollectionView.Delegate = deletate; CollectionView.RegisterClassForCell(typeof(DetailCell), _detailCellId); CollectionView.ContentInset = new UIEdgeInsets(4, 4, 4, 4); Task.Run(async() => await Refresh()); }
public void PlayVideo(Movie movie) { if (_player == null) { _player = new MPMoviePlayerController(); //_player.ControlStyle = MPMovieControlStyle.Fullscreen; _player.SourceType = MPMovieSourceType.Streaming; _player.Fullscreen = true; var center = NSNotificationCenter.DefaultCenter; _preloadObserver = center.AddObserver(NOTIFICATION_PRELOAD_FINISH, (notify)=>{ _player.Play(); notify.Dispose(); }); _playbackObserver = center.AddObserver(NOTIFICATION_PLAYBLACK_FINISH, (notify)=>{ notify.Dispose(); }); var f = this.View.Frame; _player.View.Frame = new Rectangle(0,0,(int)f.Width,(int)f.Height); this.Add(_player.View); } var url = NSUrl.FromString(movie.Url); _player.ContentUrl = url; _player.Play(); }
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); }
public override void ViewDidLoad() { base.ViewDidLoad (); //this.ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation.LandscapeRight); UIWindow window = UIApplication.SharedApplication.KeyWindow; var rootController = window.RootViewController.ChildViewControllers [0].ChildViewControllers [1]; rootController.TabBarController.TabBar.Hidden = true; this.NavigationController.NavigationBarHidden = true; moviePlayer = new MPMoviePlayerController (new NSUrl (MediaFile)); MPMoviePlayerController.Notifications.ObserveLoadStateDidChange(OnLoadStateChanged); MPMoviePlayerController.Notifications.ObservePlaybackDidFinish(OnPlaybackComplete); //moviePlayer.View.Frame = new CGRect((float)((this.View.Bounds.Width - 600) / 2), (float)((this.View.Bounds.Height - 450) / 2), 600, 400); View.AddSubview (moviePlayer.View); moviePlayer.PrepareToPlay(); moviePlayer.ShouldAutoplay = true; moviePlayer.ControlStyle = MPMovieControlStyle.Fullscreen; moviePlayer.SetFullscreen (true, true); moviePlayer.Play(); }
public void PlayVideo(string videoName) { var moviePlayer = new MPMoviePlayerController(NSUrl.FromFilename(videoName)); NavigationContext.View.AddSubview(moviePlayer.View); moviePlayer.SetFullscreen(true, true); moviePlayer.Play(); }
public bool Play() { if (_contentSet) { _moviePlayer.Play(); } return(_contentSet); }
public void PlayVideo (string path) { MPMoviePlayerController moviePlayer; moviePlayer = new MPMoviePlayerController (NSUrl.FromFilename (path)); UIApplication.SharedApplication.KeyWindow.RootViewController.Add( moviePlayer.View ); moviePlayer.ShouldAutoplay = true; moviePlayer.SetFullscreen (true,true); moviePlayer.Play (); }
void playMedia() { moviePlayer = new MPMoviePlayerController(NSUrl.FromString(url)); View.AddSubview(moviePlayer.View); moviePlayer.View.Frame = View.Frame; moviePlayer.SetFullscreen(true, true); moviePlayer.PrepareToPlay(); moviePlayer.Play(); }
partial void UIButton3_TouchUpInside(UIButton sender) { //Video File string videoFile = "Video.mp4"; MPMoviePlayerController player = new MPMoviePlayerController(NSUrl.FromFilename(videoFile)); View.AddSubview(player.View); player.SetFullscreen(true, true); player.Play(); }
public override void ViewDidLoad() { base.ViewDidLoad(); moviePlayer = new MPMoviePlayerController(new NSUrl("http://ia600507.us.archive.org/25/items/Cartoontheater1930sAnd1950s1/PigsInAPolka1943.mp4")); moviePlayer.View.Frame = new System.Drawing.RectangleF(0, 0, View.Bounds.Width, 100); //this.AddChildViewController(moviePlayer); View.AddSubview(moviePlayer.View); moviePlayer.SetFullscreen(true, true); moviePlayer.Play(); }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); if (moviePlayer != null) { moviePlayer.PrepareToPlay(); moviePlayer.Play(); } }
public override void ViewDidLoad() { base.ViewDidLoad (); moviePlayer = new MPMoviePlayerController (new NSUrl ("http://ia600507.us.archive.org/25/items/Cartoontheater1930sAnd1950s1/PigsInAPolka1943.mp4")); moviePlayer.View.Frame = new System.Drawing.RectangleF(0,0,View.Bounds.Width, 100); //this.AddChildViewController(moviePlayer); View.AddSubview (moviePlayer.View); moviePlayer.SetFullscreen (true, true); moviePlayer.Play (); }
public override void ViewDidLoad() { base.ViewDidLoad (); playMovie.TouchUpInside += delegate { moviePlayer = new MPMoviePlayerController (NSUrl.FromFilename ("sample.m4v")); View.AddSubview (moviePlayer.View); moviePlayer.SetFullscreen (true, true); moviePlayer.Play (); }; }
public override void ViewDidLoad() { base.ViewDidLoad(); playMovie.TouchUpInside += delegate { moviePlayer = new MPMoviePlayerController(NSUrl.FromFilename("sample.m4v")); View.AddSubview(moviePlayer.View); moviePlayer.SetFullscreen(true, true); moviePlayer.Play(); }; }
public override void ViewDidLoad() { base.ViewDidLoad(); Title = "Video"; btnPlay.TouchUpInside += (object sender, EventArgs e) => { moviePlayer = new MPMoviePlayerController(NSUrl.FromFilename("sample_iPod.m4v")); View.AddSubview(moviePlayer.View); moviePlayer.SetFullscreen(true, true); moviePlayer.Play(); }; }
private void playVideo(string videoFile) { MPMoviePlayerController moviePlayer = new MPMoviePlayerController(NSUrl.FromFilename(videoFile)); owner.View.AddSubview(moviePlayer.View); moviePlayer.SetFullscreen(true, true); moviePlayer.Play(); NSNotificationCenter.DefaultCenter.AddObserver( MPMoviePlayerController.PlaybackDidFinishNotification, (notification) => { moviePlayer.View.RemoveFromSuperview(); moviePlayer.Dispose(); }); }
public void InitAndPlayMovie(NSUrl url) { if (url == null){ Console.WriteLine ("The url was null"); return; } // MPMoviePlayerController is a weird singleton class, and if we let the GC collect the object // it causes unexpected behaviours, as such we explicitly dispose our previous instance if we // have one if (moviePlayer != null) { moviePlayer.Dispose (); moviePlayer = null; } moviePlayer = new MPMoviePlayerController (url); SetMoviePlayerUserSettings (); moviePlayer.Play (); }
public UIVideoView(string uriSource, CGRect frame) { this.AutoresizingMask = UIViewAutoresizing.All; this.ContentMode = UIViewContentMode.ScaleToFill; _moviePlayer = new MPMoviePlayerController(NSUrl.FromString(uriSource)); _moviePlayer.View.ContentMode = UIViewContentMode.ScaleToFill; _moviePlayer.View.AutoresizingMask = UIViewAutoresizing.All; _moviePlayer.RepeatMode = MPMovieRepeatMode.One; _moviePlayer.ControlStyle = MPMovieControlStyle.Default; _moviePlayer.ScalingMode = MPMovieScalingMode.AspectFit; _moviePlayer.MovieControlMode = MPMovieControlMode.Default; this.Frame = _moviePlayer.View.Frame = frame; Add(_moviePlayer.View); _moviePlayer.SetFullscreen(true, true); _moviePlayer.Play(); _isPlaying = true; }
void HandleMediaFileSelected(object sender, FileSelectedEventArgs args) { NavigationController.PopToViewController(this, true); try { var player = new MPMoviePlayerController(NSUrl.FromFilename(args.File)) { AllowsAirPlay = true }; View.AddSubview(player.View); player.SetFullscreen(true, true); player.PrepareToPlay(); player.Play(); } catch (Exception ex) { string message = string.Format("Error during playback of {0}: {1}", Path.GetFileName(args.File), ErrorHandling.GetExceptionDetailedText(ex)); LogMessage(message); } }
public override void ViewDidLoad() { base.ViewDidLoad(); if (media.Type == "Image") { this.View.Add(this.autoResizingImage); this.View.BackgroundColor = UIColor.White; this.Title = "Image"; } else { this.Title = "Video"; try { var nsurl = NSUrl.FromFilename((Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/" + media.URL)); //Set already instantiated MPMoviePlayerController to playback from Movies/file.m4v moviePlayer = new MPMoviePlayerController(nsurl); //enable AirPlay moviePlayer.AllowsAirPlay = true; //Add the MPMoviePlayerController View this.View.AddSubview(moviePlayer.View); //set the view to be full screen and show animated moviePlayer.SetFullscreen(false, true); //Disable the pinch-to-zoom gesture moviePlayer.ControlStyle = MPMovieControlStyle.Embedded; //MPMoviePlayer must be set to PrepareToPlay before playback moviePlayer.PrepareToPlay(); //Play Movie moviePlayer.Play(); } catch { Console.WriteLine("There was a problem playing back Video"); } } }
public Task <string> PlayVideo(string videoPath) { var task = new TaskCompletionSource <string>(); try { if (videoPath != null) { var moviePlayer = new MPMoviePlayerController(new NSUrl(videoPath)); GetController().View.AddSubview(moviePlayer.View); moviePlayer.SetFullscreen(true, true); moviePlayer.Play(); } } catch (Exception ex) { task.SetException(ex); } return(task.Task); }
public override void ViewDidLoad () { base.ViewDidLoad (); //any additional setup after loading the view, typically from a nib. //_someView = new UIView(); //_someView.Frame = window.Bounds; _moviePlayer = new MPMoviePlayerController (new NSUrl (_video.Url)); _moviePlayer.View.Frame = this.View.Frame; //_moviePlayer.ControlStyle = MPMovieControlStyle.Embedded; //_moviePlayer.Title = _video.Title; this.View.AddSubview (_moviePlayer.View); _moviePlayer.ScalingMode = MPMovieScalingMode.AspectFit; _moviePlayer.Fullscreen = true; _moviePlayer.ControlStyle = MPMovieControlStyle.Fullscreen; //this.PresentMoviePlayerViewController (_moviePlayer); //window.AddSubview(_someView); _moviePlayer.Play (); //window.MakeKeyAndVisible (); }
public override void ViewDidLoad() { base.ViewDidLoad(); //Button Events playMovieButton.TouchUpInside += delegate { try { //Set already instantiated MPMoviePlayerController to playback from Movies/file.m4v mp = new MPMoviePlayerController(NSUrl.FromFilename("Movies/file.m4v")); //enable AirPlay mp.AllowsAirPlay = true; //Add the MPMoviePlayerController View this.View.AddSubview(mp.View); //set the view to be full screen and show animated mp.SetFullscreen(true, true); //Disable the pinch-to-zoom gesture mp.ControlStyle = MPMovieControlStyle.Fullscreen; //MPMoviePlayer must be set to PrepareToPlay before playback mp.PrepareToPlay(); //Play Movie mp.Play(); } catch { Console.WriteLine("There was a problem playing back Video"); } }; }
protected override void OnElementChanged(VisualElementChangedEventArgs e) { base.OnElementChanged(e); View.BackgroundColor = UIColor.Black; var page = e.NewElement as VideoView; var fileItem = page.FileItem; UIWindow window = UIApplication.SharedApplication.KeyWindow; rootController = window.RootViewController.ChildViewControllers [0].ChildViewControllers [1].TabBarController; rootController.TabBar.Hidden = true; moviePlayer = new MPMoviePlayerController(); if (fileItem.FilePath.StartsWith ("http")) { var url = new NSUrl(fileItem.FilePath); moviePlayer.ContentUrl = url; } else { var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments); var directoryname = Path.Combine (documents, "Downloads"); var path = Path.Combine (directoryname, fileItem.FilePath); moviePlayer.ContentUrl = NSUrl.FromFilename (path); } //moviePlayer.View.Frame = new CGRect((float)((NativeView.Bounds.Width - 600) / 2), (float)((NativeView.Bounds.Height - 450) / 2), 600, 400); screenWidth = (int)UIScreen.MainScreen.Bounds.Width; screenHeight = (int)UIScreen.MainScreen.Bounds.Height; moviePlayer.View.Frame = new CGRect(0, 0, screenWidth, screenHeight); MPMoviePlayerController.Notifications.ObserveLoadStateDidChange(OnLoadStateChanged); MPMoviePlayerController.Notifications.ObservePlaybackDidFinish(OnPlaybackComplete); View.AddSubview(moviePlayer.View); moviePlayer.PrepareToPlay(); moviePlayer.ShouldAutoplay = true; //moviePlayer.SetFullscreen (true, true); moviePlayer.ControlStyle = MPMovieControlStyle.Fullscreen; moviePlayer.Play(); }
public override void WillMoveToSuperview(UIView newsuper) { if (newsuper == null) { return; } this.BackgroundColor = UIColor.Black; lblLoading = new UILabel(new CGRect(20, 20, 100, 100)); lblLoading.BackgroundColor = UIColor.Clear; lblLoading.Text = "Loading"; lblLoading.TextColor = UIColor.White; lblLoading.Font = (UIFont)(UIFont.FromName("Helvetica", 17f)); this.AddSubview(lblLoading); notificationObserver = NSNotificationCenter.DefaultCenter .AddObserver(new NSString("MPMoviePlayerPlaybackDidFinishNotification"), WillExitFullScreen); mp = new MPMoviePlayerController(MovieUrl); mp.ControlStyle = MPMovieControlStyle.Fullscreen; mp.View.Frame = (CGRect)this.Bounds; mp.SetFullscreen(true, true); this.AddSubview(mp.View); mp.Play(); }
public void ShowFullScreenVideo(string url) { if (_moviePlayer != null) { _moviePlayer.Dispose(); _moviePlayer = null; } if (_moviePlayerVC != null) { _moviePlayerVC.Dispose(); _moviePlayerVC = null; } if (App.Inst.IsIPad) { _moviePlayerVC = new MPMoviePlayerViewController(new NSUrl(url)); MVC.PresentMoviePlayerViewController(_moviePlayerVC); } else { _moviePlayer = new MPMoviePlayerController(new NSUrl(url)); _moviePlayer.Play(); } }
// ---------------------------------------------- #region Private Methods private void LoadAndPlay() { // Check the URL if (string.IsNullOrWhiteSpace(_view.Url)) { return; } var url = string.Empty; if (_view.Url.StartsWith("file://", System.StringComparison.CurrentCulture) == false) { url = $"file://{_view.Url}"; } else { url = _view.Url; } // Play the movie _controller.ContentUrl = Foundation.NSUrl.FromString(url); _controller.PrepareToPlay(); _controller.Play(); }
protected override void OnElementChanged(VisualElementChangedEventArgs e) { base.OnElementChanged(e); var page = e.NewElement as DownloadViewer; var fileItem = page.FileItem; UIWindow window = UIApplication.SharedApplication.KeyWindow; var rootController = window.RootViewController.ChildViewControllers [0].ChildViewControllers [3].TabBarController; rootController.TabBar.Hidden = true; //var url = new NSUrl.FromFilename (new Uri (fileItem.FilePath).ToString ()); moviePlayer = new MPMoviePlayerController(); var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments); var directoryname = Path.Combine (documents, "Downloads"); var path = Path.Combine (directoryname, fileItem.FilePath); moviePlayer.ContentUrl = NSUrl.FromFilename (path); screenWidth = (int)UIScreen.MainScreen.Bounds.Width; screenHeight = (int)UIScreen.MainScreen.Bounds.Height; //moviePlayer.View.Frame = new CGRect(0,(NativeView.Bounds.Height - 300)/2,NativeView.Bounds.Width,300); moviePlayer.View.Frame = new CGRect(0, 0, screenWidth, screenHeight); MPMoviePlayerController.Notifications.ObserveLoadStateDidChange(OnLoadStateChanged); MPMoviePlayerController.Notifications.ObservePlaybackDidFinish(OnPlaybackComplete); var overlayView = moviePlayer.View; View.AddSubview(overlayView); //View.AddSubview(moviePlayer.View); List<NSLayoutConstraint> constraints = new List<NSLayoutConstraint>(); constraints.Add (NSLayoutConstraint.Create (View, NSLayoutAttribute.Top, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Top, 1f, 0)); constraints.Add (NSLayoutConstraint.Create (View, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Bottom, 1f, -0)); constraints.Add (NSLayoutConstraint.Create (View, NSLayoutAttribute.Left, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Left, 1f, 0)); constraints.Add (NSLayoutConstraint.Create (View, NSLayoutAttribute.Right, NSLayoutRelation.Equal, overlayView, NSLayoutAttribute.Right, 1f, -0)); View.AddConstraints (constraints.ToArray ()); moviePlayer.PrepareToPlay(); moviePlayer.ShouldAutoplay = true; moviePlayer.SetFullscreen (true, true); moviePlayer.ControlStyle = MPMovieControlStyle.Fullscreen; moviePlayer.Play(); }
public void Play() { mp.Play(); }
public override void WillMoveToSuperview(UIView newsuper) { if (newsuper == null) return; this.BackgroundColor = UIColor.Black; lblLoading= new UILabel(new RectangleF(20,20,100,100)); lblLoading.BackgroundColor = UIColor.Clear; lblLoading.Text = "Loading"; lblLoading.TextColor = UIColor.White; lblLoading.Font = UIFont.FromName ("Helvetica", 17f); this.AddSubview(lblLoading); notificationObserver = NSNotificationCenter.DefaultCenter .AddObserver("MPMoviePlayerPlaybackDidFinishNotification", WillExitFullScreen ); mp = new MPMoviePlayerController (MovieUrl); mp.ControlStyle = MPMovieControlStyle.Fullscreen; mp.View.Frame = this.Bounds; mp.SetFullscreen(true,true); this.AddSubview(mp.View); mp.Play(); }
void HandleMediaFileSelected (object sender, FileSelectedEventArgs args) { NavigationController.PopToViewController (this,true); try { var player = new MPMoviePlayerController(NSUrl.FromFilename(args.File)) { AllowsAirPlay = true }; View.AddSubview (player.View); player.SetFullscreen (true, true); player.PrepareToPlay (); player.Play (); } catch (Exception ex) { string message = string.Format ("Error during playback of {0}: {1}", Path.GetFileName(args.File), ErrorHandling.GetExceptionDetailedText(ex) ); LogMessage (message); } }
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); }
public void Play() { moviePlayer.Play(); }
private void OpenFile(string filePath, DataItem item) { var sbounds = UIScreen.MainScreen.Bounds; string ext = UrlHelper.GetExtension(filePath); if (ext.ToUpper () == ".MOV" || ext.ToUpper () == ".M4V") { var movieController = new AdvancedUIViewController (); moviePlayer = new MPMoviePlayerController (NSUrl.FromFilename (filePath)); moviePlayer.View.Frame = new RectangleF ( sbounds.X, sbounds.Y - 20, sbounds.Width, sbounds.Height - 30 ); moviePlayer.ControlStyle = MPMovieControlStyle.Fullscreen; moviePlayer.View.AutoresizingMask = (UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight); moviePlayer.ShouldAutoplay = true; moviePlayer.PrepareToPlay (); moviePlayer.Play (); var btnClose = UIButton.FromType (UIButtonType.RoundedRect); btnClose.Frame = new RectangleF (3, 7, 60, 30); btnClose.SetTitle ("Close", UIControlState.Normal); btnClose.SetTitleColor (UIColor.Black, UIControlState.Normal); btnClose.TouchDown += delegate { movieController.DismissModalViewControllerAnimated (true); }; var btnShare = UIButton.FromType (UIButtonType.RoundedRect); btnShare.Frame = new RectangleF ( (sbounds.Width / 2) - 50, sbounds.Height - 50, 100, 30 ); btnShare.SetTitle ("Share", UIControlState.Normal); btnShare.SetTitleColor (UIColor.Black, UIControlState.Normal); btnShare.TouchDown += delegate { ResharedItem = item; ResharedItemType = FileType.Video; ShowSecretsView(); }; movieController.View.AddSubview (moviePlayer.View); movieController.View.AddSubview (btnClose); movieController.View.AddSubview (btnShare); navigation.PresentModalViewController (movieController, true); } else if (ext.ToUpper () == ".JPEG" || ext.ToUpper () == ".JPG" || ext.ToUpper () == ".PNG") { ALAssetsLibrary library = new ALAssetsLibrary (); library.AssetForUrl (new NSUrl (filePath), (asset) => { if (asset != null) { var imageController = new AdvancedUIViewController (); var image = UIImage.FromImage (asset.DefaultRepresentation.GetFullScreenImage ()); var imageView = new UIImageView (image); imageView.Frame = sbounds; imageView.UserInteractionEnabled = true; imageView.ClipsToBounds = true; imageView.ContentMode = UIViewContentMode.ScaleAspectFit; var btnClose = UIButton.FromType (UIButtonType.RoundedRect); btnClose.Frame = new RectangleF ( (sbounds.Width / 2) - 50, 20, 100, 30 ); btnClose.SetTitle ("Close", UIControlState.Normal); btnClose.SetTitleColor (UIColor.Black, UIControlState.Normal); btnClose.TouchDown += delegate { imageController.DismissModalViewControllerAnimated (true); }; var btnShare = UIButton.FromType (UIButtonType.RoundedRect); btnShare.Frame = new RectangleF ( (sbounds.Width / 2) - 50, sbounds.Height - 60, 100, 30 ); btnShare.SetTitle ("Share", UIControlState.Normal); btnShare.SetTitleColor (UIColor.Black, UIControlState.Normal); btnShare.TouchDown += delegate { ResharedItem = item; ResharedItemType = FileType.Photo; ShowSecretsView(); }; var scrollView = new UIScrollView (sbounds); scrollView.ClipsToBounds = true; scrollView.ContentSize = sbounds.Size; scrollView.BackgroundColor = UIColor.Gray; scrollView.MinimumZoomScale = 1.0f; scrollView.MaximumZoomScale = 3.0f; scrollView.MultipleTouchEnabled = true; scrollView.AutoresizingMask = (UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight); scrollView.ViewForZoomingInScrollView = delegate(UIScrollView sv) { return imageView; }; scrollView.AddSubview (imageView); imageController.View.AddSubview (scrollView); imageController.View.AddSubview (btnClose); imageController.View.AddSubview (btnShare); navigation.PresentModalViewController (imageController, true); } else { Console.Out.WriteLine ("Asset is null."); } }, (error) => { if (error != null) { Console.Out.WriteLine ("Error: " + error.LocalizedDescription); } } ); } else { var btnShare = UIButton.FromType (UIButtonType.RoundedRect); btnShare.Frame = new RectangleF ( (sbounds.Width / 2) - 50, sbounds.Height - 50, 100, 30 ); btnShare.SetTitle ("Share", UIControlState.Normal); btnShare.SetTitleColor (UIColor.Black, UIControlState.Normal); btnShare.Tag = SHARE_BUTTON_TAG; btnShare.TouchDown += delegate { ResharedItem = item; ResharedItemType = FileType.Other; ShowSecretsView(); }; navigation.Add(btnShare); interactionControllerDelegate = new UIDocumentInteractionControllerDelegateClass(navigation); interactionController = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(filePath)); interactionController.Delegate = interactionControllerDelegate; InvokeOnMainThread(delegate { interactionController.PresentPreview(true); }); } }
private void OpenFile(string filePath, DataItem item) { var sbounds = UIScreen.MainScreen.Bounds; string ext = UrlHelper.GetExtension(filePath); if (ext.ToUpper() == ".MOV" || ext.ToUpper() == ".M4V") { var movieController = new AdvancedUIViewController(); moviePlayer = new MPMoviePlayerController(NSUrl.FromFilename(filePath)); moviePlayer.View.Frame = new RectangleF( sbounds.X, sbounds.Y - 20, sbounds.Width, sbounds.Height - 30 ); moviePlayer.ControlStyle = MPMovieControlStyle.Fullscreen; moviePlayer.View.AutoresizingMask = (UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight); moviePlayer.ShouldAutoplay = true; moviePlayer.PrepareToPlay(); moviePlayer.Play(); var btnClose = UIButton.FromType(UIButtonType.RoundedRect); btnClose.Frame = new RectangleF(3, 7, 60, 30); btnClose.SetTitle("Close", UIControlState.Normal); btnClose.SetTitleColor(UIColor.Black, UIControlState.Normal); btnClose.TouchDown += delegate { movieController.DismissModalViewControllerAnimated(true); }; var btnShare = UIButton.FromType(UIButtonType.RoundedRect); btnShare.Frame = new RectangleF( (sbounds.Width / 2) - 50, sbounds.Height - 50, 100, 30 ); btnShare.SetTitle("Share", UIControlState.Normal); btnShare.SetTitleColor(UIColor.Black, UIControlState.Normal); btnShare.TouchDown += delegate { ResharedItem = item; ResharedItemType = FileType.Video; ShowSecretsView(); }; movieController.View.AddSubview(moviePlayer.View); movieController.View.AddSubview(btnClose); movieController.View.AddSubview(btnShare); navigation.PresentModalViewController(movieController, true); } else if (ext.ToUpper() == ".JPEG" || ext.ToUpper() == ".JPG" || ext.ToUpper() == ".PNG") { ALAssetsLibrary library = new ALAssetsLibrary(); library.AssetForUrl(new NSUrl(filePath), (asset) => { if (asset != null) { var imageController = new AdvancedUIViewController(); var image = UIImage.FromImage(asset.DefaultRepresentation.GetFullScreenImage()); var imageView = new UIImageView(image); imageView.Frame = sbounds; imageView.UserInteractionEnabled = true; imageView.ClipsToBounds = true; imageView.ContentMode = UIViewContentMode.ScaleAspectFit; var btnClose = UIButton.FromType(UIButtonType.RoundedRect); btnClose.Frame = new RectangleF( (sbounds.Width / 2) - 50, 20, 100, 30 ); btnClose.SetTitle("Close", UIControlState.Normal); btnClose.SetTitleColor(UIColor.Black, UIControlState.Normal); btnClose.TouchDown += delegate { imageController.DismissModalViewControllerAnimated(true); }; var btnShare = UIButton.FromType(UIButtonType.RoundedRect); btnShare.Frame = new RectangleF( (sbounds.Width / 2) - 50, sbounds.Height - 60, 100, 30 ); btnShare.SetTitle("Share", UIControlState.Normal); btnShare.SetTitleColor(UIColor.Black, UIControlState.Normal); btnShare.TouchDown += delegate { ResharedItem = item; ResharedItemType = FileType.Photo; ShowSecretsView(); }; var scrollView = new UIScrollView(sbounds); scrollView.ClipsToBounds = true; scrollView.ContentSize = sbounds.Size; scrollView.BackgroundColor = UIColor.Gray; scrollView.MinimumZoomScale = 1.0f; scrollView.MaximumZoomScale = 3.0f; scrollView.MultipleTouchEnabled = true; scrollView.AutoresizingMask = (UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight); scrollView.ViewForZoomingInScrollView = delegate(UIScrollView sv) { return(imageView); }; scrollView.AddSubview(imageView); imageController.View.AddSubview(scrollView); imageController.View.AddSubview(btnClose); imageController.View.AddSubview(btnShare); navigation.PresentModalViewController(imageController, true); } else { Console.Out.WriteLine("Asset is null."); } }, (error) => { if (error != null) { Console.Out.WriteLine("Error: " + error.LocalizedDescription); } } ); } else { var btnShare = UIButton.FromType(UIButtonType.RoundedRect); btnShare.Frame = new RectangleF( (sbounds.Width / 2) - 50, sbounds.Height - 50, 100, 30 ); btnShare.SetTitle("Share", UIControlState.Normal); btnShare.SetTitleColor(UIColor.Black, UIControlState.Normal); btnShare.Tag = SHARE_BUTTON_TAG; btnShare.TouchDown += delegate { ResharedItem = item; ResharedItemType = FileType.Other; ShowSecretsView(); }; navigation.Add(btnShare); interactionControllerDelegate = new UIDocumentInteractionControllerDelegateClass(navigation); interactionController = UIDocumentInteractionController.FromUrl(NSUrl.FromFilename(filePath)); interactionController.Delegate = interactionControllerDelegate; InvokeOnMainThread(delegate { interactionController.PresentPreview(true); }); } }