3

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

4

2 回答 2

5

由于您使用的是 JW6,因此在这行代码下:

'id': 'playerID',

添加以下内容:

'type': 'mp4',

现在,php 文件应该作为播放器的“文件”变量工作,就好了。

于 2013-06-11T17:19:12.997 回答
3

尝试:

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");

我有同样的场景(从 php 读取视频并用 jwplayer 播放)并且这个配置有效。

JS

在客户端,我将 jwPlayer 嵌入为 SWFObject。检查它是否对您有用:

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

也尝试使用绝对路径(以防万一)......

于 2013-06-07T23:31:31.133 回答