1
我正在尝试使用JWPlayer在我的网站上播放视频。但我不能得到从PHP的视频中投放动态,因为我发现了以下错误:JW Player从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)
它可以工作并提供视频。我如何从参数中动态获取视频?
我有'type':'<?php echo $ ext?>',其结果为视频类型(mp4或flv)。我仍然遇到同样的错误。我试图删除提供商,或更改为键入:mp4,但我得到相同的错误 – fareed
我可以看到一个链接? – emaxsaun
以下是使用上面相同代码的示例应用的链接http://fareed.comule.com/PhpProject1/view.php?id=1 – fareed