Reputation: 21
I am currently experimenting with HTML5 Video to see if it would be better than flash. The website I am building currently uses separate pages for each video (all the content is uploaded by me so an upload script is unnecessary) but I want to know how I would use PHP and MySQL to make a single "watch page". I would prefer this page to be standalone as I don't need anything else coded in PHP for now so the rest of my pages can use the extension .html
I can easily set up databases (server side, populating them is something im not too familiar with). I dont need a full website if ones already exist but finding the right wording for a google search is difficult (i keep finding PHP video tutorials).
<!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>
Upvotes: 1
Views: 3493
Reputation: 1
Here is the method for youtube.com Video embed Php Code:
You can see URL Here https://www.youtube.com/embed/XXX
. Here XXX
you need to put this PHP code :
<? php echo $_GET['id']; ? >
You should need to remove the space between <?
and php
from the start of the example <? php
and at the end you only need to remove space between ?
and >
. Write it like this: ?>
. Because it will not work if you keep space between them. When you do you can easily embed Youtube.com videos on your website or page. That's how you can create PHP Pages for Youtube.com.
Upvotes: -1
Reputation: 12341
Yes, you're probably gonna need a database to make this work the way you want. Let's say your page is called example.com
, and there's a video in the address example.com/watch.php?video-id=123
, what you'd want to do in your watch.php
PHP script is this:
First, retrieve the video-id
GET
parameter
$videoId = $_GET['video-id'];
Then query your database for the information about the video (I highly recommend using PDO for this)
$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);
And then, displaying the corresponding HTML
<title><?= $video['title']; ?></title>
<source src="videos/<?= $video['src']; ?>" type="video/webm">
<!-- Whatever else you need to display -->
Upvotes: 2
Reputation: 234
I read your question and I think you want to make a single watch page with your all video. If stand alone player is having a playlist its may be ok. I suggest you can use some js library you 're not necessary to learn PHP and MYSQL. I found this Library
http://mediafront.org/osmplayer/#.Uf_wrzmy_Dc
I think its very easy to use. You can download it and then you can modify your code like this in your html page.
<!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>
For playlist you create XML just change location path of video and image.
<?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>
Upvotes: 0
Reputation: 122
<?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>
i hope it will do the basic job of getting video from mysql table containing two coloumns named videokey and videoname.
Upvotes: 0