Trying to implement JW Player on iOS
Asked Answered
A

3

6

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.

Abbott answered 21/2, 2013 at 15:17 Comment(12)
Btw, flash will not play under iOS.Mol
I can't see where you call loadVideo methodMol
That should totally work, but we do just fail over to the default YouTube player on iOS. Do you have a link?Bollay
To @EthanLongTail: youtube.com/watch?v=ac7KhViaVqc.Abbott
To @Flink: should there be one? And did I configure it to be flash? And if yes, where and how should I configure it differently?Abbott
That is a link to YouTube. I want to see a link to where you are running the JW Player.Bollay
No, I saw you have swf files in your project, that's why I said about flash.Mol
@EthanLongTail what do mean? I want to run it in my appAbbott
I mean I want to be able to debug this. Can you put up something on a public facing URL for debugging purposes?Bollay
@Flink, i am really not sure my code is correct, so if you think that there is something that could correct it, go ahead and prepose.Abbott
@Abbott Check that you call [self loadVideo]; in your viewcontroller.Mol
@Flink, the app is crashing because the controller doesn't have method loadVideoAbbott
A
1

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>
Abbott answered 24/2, 2013 at 11:46 Comment(0)
F
1

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.

Fanchon answered 2/3, 2013 at 21:29 Comment(1)
Hmm. Something must not be right. That is the documented way to load resources into a UIWebView. Either way, glad you got something working.Fanchon
P
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.

Padua answered 27/6, 2019 at 0:42 Comment(1)
I think I get an Indiana Jones badge for 'excavating' and replying to a post more than 5 years old. :DPadua

© 2022 - 2024 — McMap. All rights reserved.