fareed
fareed

Reputation: 3072

JW Player read from php

I'm totally new to PHP and JW player.

I have the following code that reads a video file in php and plays it as a video file in the browser:

loadfile.php

<?php
    header("pragma : no-cache");
    header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
    header("Content-Description: File Transfer");
    header("Content-Type: video/mp4");
    header("Content-Location: videos/testvid.mp4");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".filesize("videos/testvid.mp4"));
    readfile("videos/testvid.mp4");
?>

JW player can play the video file by direct path as in here:

<div id="mediaplayer"></div>
        <script type="text/javascript">
            jwplayer('mediaplayer').setup({
                'flashplayer': 'jwplayer/jwplayer.swf',
                'file': 'videos/testvid.mp4',
                'id': 'playerID',
                'width': '480',
                'height': '320'
            });
        </script>

However, I need jw player to play the video in loadfile.php and not by direct path. In other words, I need to pass the video to JW player after streaming and reading it in php. How can I do this?

Update:

I'm using JW 6

Upvotes: 3

Views: 9610

Answers (2)

emaxsaun
emaxsaun

Reputation: 4201

Since you are using JW6, here, under this line of code:

'id': 'playerID',

Add the following:

'type': 'mp4',

Now, the php file should work as the player's "file" variable, just fine.

Upvotes: 5

Marcelo Pascual
Marcelo Pascual

Reputation: 820

Try:

clearstatcache();

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Content-Type: video/mp4");
header("Accept-Ranges: bytes");
header("Content-Length: ".filesize("videos/testvid.mp4"));
readfile("videos/testvid.mp4");

I'm having the same scenario (read video from php and play it with jwplayer) and this configuration works.

JS

On the client side, I embed jwPlayer as a SWFObject. Check if it's useful for you:

<script type="text/javascript">
$(document).ready(function(){
  var so = new SWFObject('path/to/jplayer.swf','mpl',640,480,'9');
  so.addParam('allowfullscreen','true');
  so.addParam('allowscriptaccess','always');
  so.addParam('wmode','opaque');
  so.addVariable('controlbar','over');
  so.addVariable('provider','video');
  so.addVariable('autostart','true');
  so.addVariable('file','loadfile.php');
  so.write('videoPlayer');  
});
</script>
<body>
    <div id='videoPlayer'></div>
</body>

Also try using absolute paths (just in case)...

Upvotes: 3

Related Questions