6

我是 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]];
}

函数被调用。但什么也没有发生。

4

3 回答 3

1

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

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

<script type="text/javascript"> 

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

</script>
于 2013-02-24T11:46:47.100 回答
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 中的任何相对路径都将从您的项目文件中引用。

于 2013-03-02T21:29:06.463 回答
0

In the years since this question was originally posted, JWPlayer has implemented a mobile SDK for iOS, which was at first freely available, and now is maintained exclusively for Enterprise users. There is also a new "Developer Class" account which gives full access for 6 months, free.

This post, and related issues, are perhaps the main motivator for such a move; exchanging the slippery moving target of web views, with their opaque implementation details, in favor of the controlled native environment available to a framework project was a clear win.

于 2019-06-27T00:42:35.333 回答