Skip to content

Instantly share code, notes, and snippets.

@Clancey
Created August 28, 2010 00:56
Show Gist options
  • Save Clancey/554481 to your computer and use it in GitHub Desktop.
Save Clancey/554481 to your computer and use it in GitHub Desktop.
/*
// example
MyMoviePlayer movieView = new MyMoviePlayer(window.Bounds) { MovieUrl = new NSUrl("http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8")};
movieView.Play();
movieView.Done += delegate{
movieView.RemoveFromSuperview();
}
window.AddSubview (movieView);
*/
[Register("MyMoviePlayer")]
public class MyMoviePlayer : UIView
{
MPMoviePlayerController mp;
UILabel lblLoading;
public NSUrl MovieUrl {get;set;}
public NSAction Done {get;set;}
public void Play()
{
mp.Play();
}
private NSObject notificationObserver;
public MyMoviePlayer (IntPtr handle) : base(handle)
{
}
[Export("initWithCoder:")]
public MyMoviePlayer (NSCoder coder) : base(coder)
{
}
public MyMoviePlayer (RectangleF rect): base (rect) {
}
public MyMoviePlayer () {}
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);
}
private void WillExitFullScreen( NSNotification notification)
{
if (Done != null)
Done();
}
public override void RemoveFromSuperview ()
{
lblLoading.RemoveFromSuperview();
mp.View.RemoveFromSuperview();
mp.Dispose();
NSNotificationCenter.DefaultCenter.RemoveObserver (notificationObserver);
base.RemoveFromSuperview ();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment