iPad摄像头和WebView YouTube视频播放问题
Rootviewcontroller 有一个播放 youtube 视频的 webview 它有一个拍照按钮。 用户可以单击相机按钮并录制视频。 到目前为止它工作正常
当我关闭相机控制器并尝试在网络视图中播放视频时,即使我尝试删除并再次添加视图,它的框架也会受到干扰。
当我关闭相机控制器而不录制视频时,它工作正常...... 这是图像 播放视频的代码
GDataEntryBase *entry2 = [[AppDelegate.feed entries] objectAtIndex:[tag intValue]];
NSArray *contents = [[(GDataEntryYouTubeVideo *)entry2 mediaGroup] mediaContents];
NSString *urlString=[NSURL URLWithString:[[contents objectAtIndex:0] URLString]];
NSString *embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: black;\
color: black;\
}\
</style>\
</head><body style=\"margin:0\"><div>\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"736\" height=\"571\"></embed></div>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, urlString, webplay.frame.size .width, webplay.frame.size.height];
NSLog(@"html=%@",html);
[webplay loadHTMLString:html baseURL:nil];
Rootviewcontroller has a webview that plays a youtube video
and it has one camera button.
User can click on camera button and record video.
up to this point its working fine
When I dismiss the camera controller and try to play the video in webview, its frame gets disturbed even though I tried removing and again adding on view.
When I dismiss the camera controller without recording the video its working ok...
Here is the image
code to play video
GDataEntryBase *entry2 = [[AppDelegate.feed entries] objectAtIndex:[tag intValue]];
NSArray *contents = [[(GDataEntryYouTubeVideo *)entry2 mediaGroup] mediaContents];
NSString *urlString=[NSURL URLWithString:[[contents objectAtIndex:0] URLString]];
NSString *embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: black;\
color: black;\
}\
</style>\
</head><body style=\"margin:0\"><div>\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"736\" height=\"571\"></embed></div>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, urlString, webplay.frame.size .width, webplay.frame.size.height];
NSLog(@"html=%@",html);
[webplay loadHTMLString:html baseURL:nil];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在单击取消按钮时再次加载整个视图。
you can load your entire view again on cancel button click.
使用 webviewcontroller 播放电影会带来很多问题(例如旋转)。使用专门的电影课程总是一个更好的主意。
如果由于某种原因您仍然需要使用 webview,我发现:
- 在临时变量中设置 RootViewController
- 将 RootViewController 设置为 nil
- 使用存储变量的内容再次恢复 RootViewController
整个视图堆栈被重新初始化,并且将解决我在旋转变得奇怪时遇到的很多问题。小武知道这个“黑客”也可能对你有用。
Playing movies by using the webviewcontroller gives a lot of issues (for instance with rotation). It's always a better idea to use the dedicated movie classes.
If you still need to use the webview for some reason or the other, I found out that by:
- setting the RootViewController in a temp variable
- setting the RootViewController to nil
- restoring the RootViewController again with the contents of the stored variable
the whole viewstack is reinitialized and would solve a lot of the issues I had with the rotation going weird. Wo knows the 'hack' might work for you as well.
我确实检查过,但这是层问题,我使用命中测试来解决这个问题。
以下链接展示了如何使用命中测试
I did check but it was layer problem I used hit test to solve this problem.
Here is a link that show how to use hit test
您需要“
”标签吗?尝试删除它们,看看会发生什么。
另外,下面的链接对我有用,它提供了很好的示例代码。我改变了使用 YouTube 的方式来适应这个模型,并且能够轻松地构建一个由单元格中的 YouTube 链接填充的表格。当您点击单元格时,视频将在一帧内播放。
http://iosdevelopertips.com/video/display- youtube-videos-without-exiting-your-application.html
希望这会有所帮助。
Do you need the "
<div>
" tag? Try removing them as see what happens.Also, this link below worked for me and it provides good sample code. I altered the way I was using YouTube to fit this model and was easily able to build a table populated by youtube links in the cells. As you tapped on the cells, the video would play within a frame.
http://iosdevelopertips.com/video/display-youtube-videos-without-exiting-your-application.html
Hope this helps.