在 Uiwebview 内显示视频而不是设备全屏

Display video inside the Uiwebview not in device full screen(在 Uiwebview 内显示视频而不是设备全屏)
本文介绍了在 Uiwebview 内显示视频而不是设备全屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想在 UIWebview 中显示视频.当我们点击视频时,它会全屏播放.

I want to display video inside the UIWebview. When we click on the video it plays in device full screen.

我们如何在 UIWebview 中播放视频?请注意,这些视频文件托管在 youtube 或我们的服务器上.它们不与应用程序捆绑在一起

How do we play video inside the UIWebview? Please note that these video files are hosted on youtube or on our server. they are not bundled along with app

推荐答案

要在 UIWebView 中播放视频,请使用以下代码......

To play video in UIWebView use below code....

NSString *strVedio = @"<video controls> <source src="YourVideo.mp4"> </video>";
NSString *path = [[NSBundle mainBundle] pathForResource:@"YourVideo" ofType:@"mp4"];
[Webview loadHTMLString:strVedio baseURL:[NSURL fileURLWithPath:path]];

更新:

使用下面的代码在 UIWebView 中从视频 URL 显示视频...

use this below code to display video in UIWebView from video URL...

  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 *strHtml = [NSString stringWithFormat:embedHTML, yourURLString, width,height];//set width and height which you want

  [webView loadHTMLString:strHtml baseURL:nil];
  [self.view addSubview:webView];

如果您只想在小屏幕上显示而没有 webview,请使用下面的代码..

If you want to display in small screen only and without webview then use bellow code..

MPMoviePlayerController *videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
[player setControlStyle:MPMovieControlStyleNone];

player.view.frame = CGRectMake(0, 0, 150, 150);

[self.view addSubview:videoPlayer.view];

这篇关于在 Uiwebview 内显示视频而不是设备全屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
Resume game cocos2d(恢复游戏 cocos2d)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)