从php读取的JW Player无法动态读取视频

时间:2013-10-04 17:48:37

标签: php video jwplayer

我正在尝试使用JWPlayer在我的网站上播放视频。但我无法动态地从php提供视频,因为我收到以下错误:

Error loading media: File could not be played

我目前的代码是:

<?php
   include('connection.php');//connect to db
   $id = $_GET['id'];//get video id from param
   $video = mysql_query("SELECT * FROM video_table WHERE id = '$id'");//video row from db
   $data = mysql_fetch_assoc($video);
   $ext = pathinfo($data['video_name'], PATHINFO_EXTENSION);
   $file_name = $id . "." . $ext;
   echo $file_name;
?>
   <div id="container1"></div>
       <script type="text/javascript">
            jwplayer('container1').setup({
                'id': 'container1',
                'type': '<?php echo $ext ?>',
                'wmode': 'transparent',
                'flashplayer': 'jwplayer/jwplayer.flash.swf',
                'file': 'video.php',
                'provider': 'video',
                'width': '480',
                'height': '320',
            });
        </script>
   </div>

video.php

<?php
    include('connection.php');
    $id = $_GET['id'];
    $video = mysql_query("SELECT * FROM video_table WHERE id = '$id'");
    $data = mysql_fetch_assoc($video);
    $ext = pathinfo($data['video_name'], PATHINFO_EXTENSION);
    $type = pathinfo($data['type'], PATHINFO_EXTENSION);
    $file_name = $id . "." . $ext;//set the file name as saved in upload directory e.g: 1.mp4

    header("pragma : no-cache");
    header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
    header("Content-Description: File Transfer");
    header("Content-Type: $type");
    header("Content-Location: upload/$file_name");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".filesize("upload/$file_name"));
    readfile("upload/$file_name");
?>

但是,如果我在此更改了绝对名称(upload/1.mp4) instead of (upload/$file_name),则可以使用并提供视频。如何从参数中动态获取视频?

1 个答案:

答案 0 :(得分:1)

变化:

'provider': 'video',

要:

'type': 'mp4',

如果您使用FLV而不是MP4,请将其设为:

'type': 'flv',

此外:

这里有一些事情。您仍然将提供商设置为视频,我会删除它。您也将文件作为video.php拉入,但没有设置ID。现在你正在使用 - 'file':'video.php',我会把它改成video.php?id = 1,我也会从6.4更新到6.6。