我正在尝试在我的应用程序中播放 youtube 视频。这是我正在使用的代码
- (void)embedYouTube:(NSString*)url frame:(CGRect)frame {
NSString* embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString* html = [NSString stringWithFormat:embedHTML, url, frame.size.width, frame.size.height];
if(videoView == nil) {
videoView = [[UIWebView alloc] initWithFrame:frame];
[self.view addSubview:videoView];
}
[videoView loadHTMLString:html baseURL:nil];
}
视频播放效果很好。但是播放完视频后
- 我被带回 Root View Controller 而不是 View 调用上面的函数。
- 此外,在 Root View Controller 中, View 未处于事件状态。我不能 单击该 View 中的任何按钮。
- 我还可以在 View 底部看到一个 20px 的空白空间,看起来 就像 View 占用了状态栏的空间
我怎样才能在 ios 中正确地做到这一点? 谢谢
最佳答案
我也遇到过同样的问题。
只需为没有 .xib 文件的 Uiwebview 创建自定义类并实现您的代码。
只需在要播放视频的 View 中创建自定义类的对象即可。
但不要将它添加到 View 中,只需创建对象并传递视频 url。
关于iphone - 在 iphone 中播放 youtube 视频的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7619857/