本文介绍了尝试在iOS上实现JW Player的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JW的新手,似乎无法实现最简单的播放器.请帮帮我.

I am a newbi in JW and can't seem to implement to simplest player. Help me, please.

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

I have created an html and put it in my project. in the same place with the jwplayer.flash.swf, jwplayer.html5.js, jwplayer.js

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

My html file looks like this (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]];
}

这些函数被调用.但是什么也没发生.

The functions are called. But nothing happens.

推荐答案

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

I found the problem:UIWebView doesn't have access to project files. So the jwplayer.js is not loaded. So either load the player to some web server, or replace

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

<script type="text/javascript"> 

文件jwplayer.js的内容 (右键单击jwplayer.js->查看源代码->复制->粘贴到此处)

Content of the file jwplayer.js (right click on jwplayer.js -> view source -> copy -> paste to here)

</script>

这篇关于尝试在iOS上实现JW Player的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 14:24