2013-08-05 129 views
1

我目前正在試驗HTML5視頻,看看它是否會比Flash更好。我正在構建的網站爲每個視頻使用不同的頁面(所有內容都由我上傳,因此不需要上傳腳本),但我想知道如何使用PHP和MySQL創建單個「觀看頁面」。我寧願這個頁面是獨立的,因爲我現在不需要任何其他的PHP編碼,所以我的其餘頁面可以使用擴展名.html我可以很容易地設置數據庫(服務器端,填充它們是我不太熟悉的東西)。我不需要一個完整的網站,如果已經存在,但尋找谷歌搜索正確的措辭是困難的(我一直在尋找PHP視頻教程)。製作視頻「觀看頁面」

<!DOCTYPE html> 
<html> 
<head> 
<title>Video Title - FTVO</title> 
<meta charset="UTF-8"> 
</head> 
<body> 
<h2>Video Title</h2> 
<p>Watch this episode using the player below</p> 
<h3>Getting a "Unsupported" error? Fix it by upgrading your browser. We recommend Firefox.</h3> 
<a href="http://www.mozilla.org/en-US/firefox/new/"><img src="images/firefoxbanner.png" alt="FirefoxBanner"/></a> 
<br /> 
<video width="640" height="480" controls> 
<source src="videos/e1.webm" type="video/webm"> 
Your Browser Doesn't Support this Element 
</video> 
<hr> 
<p>This site is property of <b>TechXtra Web Services</b></p> 
</body> 
</html> 
+1

你能提供相關的代碼和更多的細節嗎?你有沒有想要解決的具體問題/問題? – 2013-08-05 18:08:53

+0

你已經有Flash版本了嗎?你現在想要觀看的視頻如何填充它? – kalley

+0

所有我試圖做的是使用HTML5和PHP一起爲我的所有內容製作一個頁面。例如:

回答

2

是的,你可能會需要一個數據庫,使其按照你想要的方式工作。比方說,你的網頁被稱爲example.com,並有在地址example.com/watch.php?video-id=123的視頻,你會希望在你的watch.phpPHP腳本做的是這樣的:

首先,檢索video-idGET參數

$videoId = $_GET['video-id']; 

然後查詢數據庫有關視頻的信息(我強烈建議使用PDO此)

$mysqli = new mysqli($host, $user, $pass, $db); 
$sql = " 
     SELECT id, title, src 
     FROM videos 
     WHERE id = $videoId 
     LIMIT 1 
"; 
$result = $mysqli->query($sql); 
$video = mysqli_fetch_array($result, MYSQLI_ASSOC); 
mysqli_close($mysqli); 

而且然後,並顯示相應的HTML

<title><?= $video['title']; ?></title> 

<source src="videos/<?= $video['src']; ?>" type="video/webm"> 

<!-- Whatever else you need to display --> 
+0

由上面的shashikant發佈,這將連接到我的分貝:$ connect = myqli_connect('localhost,'dbusername','dbpassword,'dbname'); (顯然改變服務器,用戶名,密碼和數據庫名稱)?我也會正確地說,所有的mysql的東西都需要包含在<?php *腳本去這裏*?>? – JWassall

+0

@JWassall我已經更新了我的答案,向您展示瞭如何創建與數據庫的連接(顯然,更改參數)。並非如此,在這種情況下,要訪問查詢結果,您只需執行'$ video ['<列的名稱>']'。如果你想在HTML中顯示它,使用'<?php echo $ video ['<列的名稱>']?>'。 – federicot

+0

我認爲我需要在php頁面(<!DOCTYPE html>等)中使用所有標準的html東西?另外當鏈接到我的數據庫中的視頻源時,我會使用'http:// example.com/video/123.webm'(我的mysql服務器單獨託管,因爲我使用webhosting公司) – JWassall

0
<?php 
    $videokey = $_REQUEST['key']; 
    $connect = myqli_connect('localhost,'dbusername','dbpassword,'dbname'); 
    $SQL = "SELECT 'videoname' where videokey = $videokey "; 
    $query = mysqli_query($SQL); 
    $result = mysqli_fetch_array($query, MYSQLI_ASSOC); 
?> 
<html> 
<body> 
<video width="320" height="240" controls> 
<source src="<?php echo $result["videoname"];?>" type="video/mp4"> 
</video> 

我希望它會做含有名爲videokey和videoname 2個coloumns MySQL表獲取視頻的基本工作。

+0

這真的很有幫助謝謝。我是否可以另外添加一個videotitle專欄,以便我可以動態地在head標籤中命名頁面? <?php echo $ result [「videotitle」];?>工作? – JWassall

+0

是的,當然,它會工作 –

0

我讀了你的問題,我想你想使一個單一的觀看頁面所有視頻。 如果獨立播放器正在播放列表,則可能沒問題。我建議你可以使用一些js庫,你不需要學習PHP和MYSQL。我發現這個圖書館

http://mediafront.org/osmplayer/#.Uf_wrzmy_Dc

我認爲它非常容易使用。你可以下載它,然後你可以在你的html頁面中像這樣修改你的代碼。

<!DOCTYPE html> 
<html> 
<head> 
<title>Video Title - FTVO</title> 
<meta charset="UTF-8"> 
<!-- Include the core jQuery and jQuery UI --> 
<script type='text/javascript' src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script> 
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script> 

<!-- Include the core media player JavaScript. --> 
<script type="text/javascript" src="osmplayer/bin/osmplayer.compressed.js"></script> 

<!-- Include the DarkHive ThemeRoller jQuery UI theme. --> 
<link rel="stylesheet" href="osmplayer/jquery-ui/dark-hive/jquery-ui.css"> 

<!-- Include the Default template CSS and JavaScript. --> 
<link rel="stylesheet" href="osmplayer/templates/default/css/osmplayer_default.css"> 
<link rel="stylesheet" href="osmplayer/templates/default/osmplayer.default.js"> 
<script type="text/javascript"> 
    $(function() { 
     $("#osmplayer").osmplayer({ 
      playlist: 'playlist.xml', 
      width: '480px', 
      height: '640px' 
     }); 
    }); 
</script> 
</head> 
<body> 
<h2>Video Title</h2> 
<p>Watch this episode using the player below</p> 
<div id="osmplayer"></div> 
<hr> 
<p>This site is property of <b>TechXtra Web Services</b></p> 
</body> 
</html> 

對於播放列表,您創建XML只是更改視頻和圖像的位置路徑。

<?xml version="1.0" encoding="UTF-8"?> 
    <playlist version="1" xmlns="http://xspf.org/ns/0/"> 
     <trackList> 
      <track> 
      <title>HTML5: Matagascar III</title> 
      <location>http://progressive.totaleclips.com.edgesuite.net/105/e105598_257.mp4</location> 
      <image>http://www.movieposter.com/posters/archive/main/143/MPW-71686</image> 
      </track> 
      <track> 
      <title>HTML5: Snow White and the Huntsman</title> 
       <location>http://progressive.totaleclips.com.edgesuite.net/103/e103981_257.mp4</location> 
      <image>http://www.movieposter.com/posters/archive/main/142/MPW-71148</image> 
      </track> 
      <track> 
      <title>HTML5: Men in Black III</title> 
      <location>http://progressive.totaleclips.com.edgesuite.net/105/e105857_257.mp4</location> 
      <image>http://www.movieposter.com/posters/archive/main/146/MPW-73434</image> 
      </track> 
    </trackList> 
</playlist> 
+0

由於我不喜歡JavaScript,我寧願只使用HTML和PHP。這並不是說其難或者別的什麼,但我想嘗試只使用HTML和PHP爲儘可能多地。這個網站更像是一個教育項目,而不是其他任何東西。 – JWassall

+0

好吧,我不知道你想學習PHP的那麼我的答案是沒有這種情況的解決方案。對此很抱歉。 – cavaliercyber