Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 617
Luda Avatar asked Feb 21 '13 15:02

Luda


People also ask

Does JW Player work on Iphone?

Requires iOS 8.0 or later.

Why JW Player is not working?

To fix JW player not working in Chrome, open settings after clicking on the three dot icon at the right, then choose Advanced. Fetch for Reset settings by scrolling down, It will ask for confirmation. Click on YES. Then restart your Chrome after this process gets complete.

What is the latest version of JW Player?

8.24. 0 is our final release of 2021.


2 Answers

You actually can access local files from within the HTML of a UIWebview. Just change your code as such:

-(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];
}

Any relative paths in your HTML will then be referenced from your project files.

like image 71
Josh Hudnall Avatar answered Oct 18 '22 10:10

Josh Hudnall


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>
like image 42
Luda Avatar answered Oct 18 '22 09:10

Luda