Created
July 14, 2010 01:23
-
-
Save martinbowling/474859 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using MonoTouch; | |
using MonoTouch.UIKit; | |
using System.Drawing; | |
using MonoTouch.Foundation; | |
using System.Text; | |
using System.IO; | |
namespace MRB | |
{ | |
public class EmbeddedVideoViewController : UIViewController | |
{ | |
UIWebView webView; | |
public string videoUrl; | |
public string posterUrl; | |
public string title; | |
public readonly static string BaseDir = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), ".."); | |
public EmbeddedVideoViewController (string Title, string VideoUrl, string PosterUrl) | |
{ | |
title = Title; | |
videoUrl = VideoUrl; | |
posterUrl = PosterUrl; | |
} | |
public override void ViewDidLoad () | |
{ | |
base.ViewDidLoad (); | |
this.NavigationItem.Title = title; | |
webView = new UIWebView (){ | |
ScalesPageToFit = true, | |
MultipleTouchEnabled = true, | |
AutoresizingMask = UIViewAutoresizing.FlexibleHeight|UIViewAutoresizing.FlexibleWidth, | |
}; | |
webView.LoadStarted += delegate { | |
UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; | |
}; | |
webView.LoadFinished += delegate { | |
UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; | |
}; | |
string html = getEmbeddedVideoHtml(); | |
webView.LoadHtmlString(html, new NSUrl(BaseDir, true)); | |
webView.ScalesPageToFit = false; | |
this.View.AddSubview(webView); | |
} | |
public string getEmbeddedVideoHtml() | |
{ | |
return "<video width='480' height='320' poster='" + posterUrl +"' controls autoplay><source src='" + videoUrl + "' type='video/mp4'></video>"; | |
} | |
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation) | |
{ | |
return toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown; | |
} | |
public override void DidRotate (UIInterfaceOrientation fromInterfaceOrientation) | |
{ | |
base.DidRotate (fromInterfaceOrientation); | |
LayoutViews (); | |
} | |
void LayoutViews() | |
{ | |
var sbounds = View.Bounds; | |
int top = (InterfaceOrientation == UIInterfaceOrientation.Portrait) ? 0 : -44; | |
webView.Frame = new RectangleF (0, top, sbounds.Width, sbounds.Height); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment