开发者

Video in UIView (or UIWebView)

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜