如何在uiwebview中显示支持HTML5的视频?

时间:2011-04-01 05:01:24

标签: objective-c ios4 uiwebview

我必须使用uiwebview在我的iphone应用程序中显示支持HTML5的视频。如何解决这个问题?任何有想法的人都请提供示例代码。

我的代码显示视频:

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];

1 个答案:

答案 0 :(得分:2)

我很确定它默认应该支持这个。主要问题是the HTML part

但什么不起作用?因为看到你的标签,我认为你不是制作网站的人,但UIWebView根本不会显示视频?

修改:查看帖子UIWebView to Play Local and downloaded Video,或者更具体地说,查看此答案:

解决方案就在这里,您可以在嵌入式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];
}