UIView(或 UIWebView)中的视频
我想知道我是否可以在 UIView
中播放视频?
我想在一个小的 UIView
(例如 100 x 100 )中播放视频,该视频应该在 UIView
加载时自动播放。
首先我想说一下我尝试过的...如果专家(我是一个 IOS 开发和 Obj-C 中的 2 周大婴儿)确认我前进的路线是否正确,那将会非常有帮助..
我创建了UIWebView 并尝试使用 HTML 视频标签 (html5) 在其中嵌入视频 对于 UIWebview
,我将 allowInlineMediaPlayback
设置为 YES,将 mediaPlaybackRequiresUserAction
设置为 NO ...另外,在 HTML 代码中,对于视频标签,我使用了- webkit-playsinline。
非常感谢任何帮助。
更新
这是我的html块代码...我确实添加了播放视频JS ....但是当我在模拟器中运行应用程序时,我没有得到视频,只得到音频。
NSString *embedHTML = @"\
<!DOCTYPE HTML>\
<html>\
<head>\
<script type=\"text/javascript\">\
function playvideo() {\
var myVideo=document.getElementsByTagName('video')[0];\
myVideo.play();\
myVideo.webkitExitFullscreen();\
myVideo.height = 120;\
myVideo.width = 120;\
}\
</script>\
</head>\
<body onLoad = \"playvideo()\" >\
<video id=\"player\" webkit-playsinline width=\"140\" height=\"140\">\
<source src=\"file:///Users/Shilpa/Desktop/Movie Player/MoviePlayer-ios4-Next/Movie-1.mp4\"/>\
</video>\
</body>\
</html>";
webView = [[UIWebView alloc] initWithFrame:CGRectMake(100.0, 170.0, 150.0, 150.0)];
[webView setOpaque:YES];
NSString *html = [NSString stringWithFormat:embedHTML, webView.frame.size.width, webView.frame.size.height];
[webView loadHTMLString:html baseURL:nil];
webView.allowsInlineMediaPlayback = YES;
webView.mediaPlaybackRequiresUserAction = NO;
webView.transform = CGAffineTransformMakeRotation(3.14/2);
[moviePlayerWindow addSubview:webView];
I would like to know if I can play a video in UIView
?
I want to play a video in a small UIView
(say 100 x 100 ) which should be played automatically when the UIView
loads.
First I would say what I tried out ... It would be really helpful if the experts ( I am a 2 week old baby in IOS development & Obj- C) to confirm whether the route I am heading is right..
I created a UIWebView and and tried to embed a video in it using HTML video tag (html5)
For the UIWebview
I set the allowInlineMediaPlayback
to YES and mediaPlaybackRequiresUserAction
to NO ... Also in the HTML code, for the video tag, I used - webkit-playsinline.
Any help is much appreciated.
Update
This is my code with my html block ... I did add the play video JS .... But when I run the app in simulator , I do not get the video , only get audio.
NSString *embedHTML = @"\
<!DOCTYPE HTML>\
<html>\
<head>\
<script type=\"text/javascript\">\
function playvideo() {\
var myVideo=document.getElementsByTagName('video')[0];\
myVideo.play();\
myVideo.webkitExitFullscreen();\
myVideo.height = 120;\
myVideo.width = 120;\
}\
</script>\
</head>\
<body onLoad = \"playvideo()\" >\
<video id=\"player\" webkit-playsinline width=\"140\" height=\"140\">\
<source src=\"file:///Users/Shilpa/Desktop/Movie Player/MoviePlayer-ios4-Next/Movie-1.mp4\"/>\
</video>\
</body>\
</html>";
webView = [[UIWebView alloc] initWithFrame:CGRectMake(100.0, 170.0, 150.0, 150.0)];
[webView setOpaque:YES];
NSString *html = [NSString stringWithFormat:embedHTML, webView.frame.size.width, webView.frame.size.height];
[webView loadHTMLString:html baseURL:nil];
webView.allowsInlineMediaPlayback = YES;
webView.mediaPlaybackRequiresUserAction = NO;
webView.transform = CGAffineTransformMakeRotation(3.14/2);
[moviePlayerWindow addSubview:webView];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HTML 视频标签,可能需要通过 JavaScript 执行操作,
尝试将以下代码放入您的 html 页面中,
并看到神奇的效果:)
我相信,只能播放您正在使用 WebView 的视频,但您也可以使用 QTView 来执行相同的操作。
HTML Video tag, might needs an action via JavaScript,
try to put following code in your html page,
and see the magic :)
i believe, only to play the video you are using WebView, but you can use the QTView also to do the same.