Search code examples
iphoneiosobjective-cjwplayer

Trying to implement JW Player on iOS


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

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

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>

in the controller class:

- (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.


Solution

  • 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>
    

    with

    <script type="text/javascript"> 
    

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

    </script>