0

I have to show HTML5 enabled videos in my iphone application using the uiwebview. How to resolve this problem? Any one having idea please give with example code.

My code to show the video:

NSString *filepath = [[NSBundle mainBundle] pathForResource:@"Movie-1" ofType:@"mp4"]; 
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
movie_obj = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; 
[movie_obj.view setFrame:CGRectMake(0,0,320,460)];
movie_obj.scalingMode=MPMovieScalingModeAspectFit; 
[self.view addSubview:movie_obj.view]; 
[movie_obj play];
j0k
  • 22,600
  • 28
  • 79
  • 90
Senthilkumar
  • 2,471
  • 4
  • 30
  • 50
  • 'How to resolve this problem?' What problem exactly? What is not working about it? Does it give an error message, or does simply nothing happen? Please be a little more clear ;) – Erik S Apr 04 '11 at 14:23

1 Answers1

2

I'm quite sure it should support this by default. The main problem would be the HTML part.

But what doesn't work? Because seeing your tags, i think you're not the one making the site, but the UIWebView simply won't show the video?

Edit: check out the post UIWebView to Play Local and downloaded Video or, more specifically, this answer:

Solution is here, you can play video in Embedded UIWebView.

- (void)viewDidLoad {

[super viewDidLoad];

NSString *embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"http://www.businessfactors.de/bfcms/images/stories/videos/defaultscreenvideos.mp4\" type=\"application/x-shockwave-mp4\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";

webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 412.0)];

[webView setOpaque:NO];
NSString *html = [NSString stringWithFormat:embedHTML, webView.frame.size.width, webView.frame.size.height];
[webView loadHTMLString:html baseURL:nil];

[self.view addSubview:webView];
}
Community
  • 1
  • 1
Erik S
  • 1,939
  • 1
  • 18
  • 44
  • thanks Erik Dolor, NSString *filepath = [[NSBundle mainBundle] pathForResource:@"Movie-1" ofType:@"mp4"]; NSURL *fileURL = [NSURL fileURLWithPath:filepath]; movie_obj = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; [movie_obj.view setFrame:CGRectMake(0,0,320,460)]; movie_obj.scalingMode=MPMovieScalingModeAspectFit; [self.view addSubview:movie_obj.view]; [movie_obj play]; I got coding regarding video show in uiwebview? – Senthilkumar Apr 04 '11 at 12:17
  • I added your code to your initial post, this will make it much more readable for others. But if i get you right, you're simply trying to show a MP4 video you saved in your resources using a UIWebView? – Erik S Apr 04 '11 at 14:22
  • your code works but when i open the video in player. and when tap back button. it shows white color over the navigation bar and shifts the navigation bar below that white space. any help will be appreciated. – abhiTouchmagic Jan 06 '12 at 09:42