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.

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

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘