UIView(或 UIWebView)中的视频

发布于 2024-10-24 09:20:58 字数 1796 浏览 5 评论 0原文

我想知道我是否可以在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠檬心 2024-10-31 09:20:58

HTML 视频标签,可能需要通过 JavaScript 执行操作,
尝试将以下代码放入您的 html 页面中,

<body onload = playvideo() > 

并看到神奇的效果:)

我相信,只能播放您正在使用 WebView 的视频,但您也可以使用 QTView 来执行相同的操作。

HTML Video tag, might needs an action via JavaScript,
try to put following code in your html page,

<body onload = playvideo() > 

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文