试图在iOS上实现JW Player

时间:2013-02-21 15:17:46

标签: iphone ios objective-c jwplayer

我是JW的新手,似乎无法实现最简单的玩家。请帮帮我。

我创建了一个html并将其放入我的项目中。与jwplayer.flash.swf,jwplayer.html5.js,jwplayer.js在同一个地方

我的html文件如下所示(Home.html):

<html>
<head>
  <title>Title of the document</title>
  <script type="text/javascript" src="jwplayer.js"></script>
  <script type="text/javascript">jwplayer.key="myKey"</script>
</head>
<body>
  <div id='player_8955'></div>
  <script type='text/javascript'>
    jwplayer('player_8955').setup({
      file: "http://www.youtube.com/watch?v=ac7KhViaVqc",
      width: "480",
      height: "270",
      image: "http://content.bitsontherun.com/thumbs/3XnJSIm4-640.jpg",
    });
  </script>
</body>
</html>

在控制器类中:

- (void)viewDidLoad
{
    [super viewDidLoad];
    htmlPlayerWebView=[[UIWebView alloc]initWithFrame:CGRectMake(20, 51, 674,381)];
    [self.view addSubview:htmlPlayerWebView];
}
-(void)loadVideo
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Home" ofType:@"html"];
    NSString *HTMLString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
    [htmlPlayerWebView loadHTMLString:HTMLString baseURL:[NSURL URLWithString:path]];
}

调用这些函数。但没有任何反应。

3 个答案:

答案 0 :(得分:3)

我发现了问题: UIWebView无权访问项目文件。所以没有加载jwplayer.js。 因此要么将播放器加载到某个Web服务器,要么替换

<script type="text/javascript" src="jwplayer.js"></script>

<script type="text/javascript"> 

文件内容jwplayer.js (右键点击jwplayer.js - &gt;查看来源 - &gt;复制 - &gt;粘贴到此处)

</script>

答案 1 :(得分:1)

您实际上可以从UIWebview的HTML中访问本地文件。只需更改您的代码:

-(void)loadVideo
{
    NSString *basePath = [[NSBundle mainBundle] bundlePath];
    NSURL *baseURL = [NSURL fileURLWithPath:basePath];

    NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"Home" ofType:@"html"];
    NSString *HTMLString = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];

    [htmlPlayerWebView loadHTMLString:HTMLString baseURL:baseURL];
}

然后,您的HTML中的任何相对路径都将从您的项目文件中引用。

答案 2 :(得分:0)

自最初发布此问题以来,多年来,JWPlayer实施了mobile SDK for iOS,该软件最初免费提供,现在仅面向企业用户维护。还有一个新的“开发人员类别”帐户,可以免费使用6个月的完整访问权限。

此帖子以及相关问题,可能是此举的主要动机;交换具有不透明的实现细节的Web视图的滑动目标,以支持可用于框架项目的受控本机环境是一个明显的胜利。