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.
Requires iOS 8.0 or later.
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.
8.24. 0 is our final release of 2021.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With