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