duanniu3385 2013-10-04 17:48
浏览 81
已采纳

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

I am trying to use JWPlayer to play videos on my website. But I cannot get the video served from php dynamically as I'm getting the following error:

Error loading media: File could not be played

My current code is:

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

However, if I changed the absolute name here (upload/1.mp4) instead of (upload/$file_name) it works and video is provided. How can I get the video dynamically from parameter?

  • 写回答

1条回答 默认 最新

  • dpafea04148 2013-10-04 18:13
    关注

    Change:

    'provider': 'video',
    

    To:

    'type': 'mp4',
    

    If you are using FLV instead of MP4, make it:

    'type': 'flv',
    

    Also:

    A few things here. You still have provider set to video, I would remove that. Also you are pulling file in as video.php, but there is no ID set. Right now you are using - 'file': 'video.php', I would change it to video.php?id=1, also I would update from 6.4 to 6.6.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂