Making a Video Player.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Making a Video Player.

Post by nickman013 »

I would like to make a very simple video player.

I have a lot of videos I want to include in this page.

I think I would need to set up a array of all the videos?

And then

Code: Select all

<embed src=<? echo $array[number] ?> other attributes>
I am not sure.

Basically what I want to do is this.

I have a video page, with alot of videos. I want the videos to just be played from one page.

For example. If the links are

Code: Select all

<a href=/playvideo?videoname=myvideo>Play My Video!</a>
Then this will open up the playvideo page and play myvideo.

Do you get what I mean.

I was thinking of how to do it, and I thouht to make a array of all the videos. But I do not know if that would be the best way. Can you guys please help me get started. Thank You!

EDIT: I just read this to myself, I repeat myself so much. LOL thanks!
nincha
Forum Contributor
Posts: 191
Joined: Fri Mar 28, 2003 12:30 pm
Location: CA, USA

Post by nincha »

name yuor videos video0, video1, video2, video3,....... video[max]

Code: Select all

for($i=0; $i<=max;$i++){

echo "<a href=/playvideo?videoname=video".$i.">Play My Video!</a>"; 

}
and for other page

Code: Select all

<embed src=<? echo $_GET["videoname"] ?> other attributes>
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Don't forget a <br /> and \n at the end of that echo. ;)
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Can i make it video[with a name in here] so for example.. video[joes] ?

will that work?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

yes
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

nickman013 wrote:Can i make it video[with a name in here] so for example.. video[joes] ?

will that work?
The best approach at this IMO would be to store all the file names into a database .. this way you can better organize things and benfit from others features you could possibly add.

Code: Select all

<?php 
$clause = '';
if (!empty($_GET['id'])) {
   $clause  = 'WHERE '; 
   $clause .=  (is_numeric($_GET['id']) 
      ? '`id` ';
      : '`fileName` '
   );
   $clause .= '= \''. mysql_real_escape_string($_GET['id']) .'\' LIMIT 1'; 
}
   
$sql = 'SELECT `fileName` FROM `videos` '. $clause .'; ?>
This will allow you to pass links as a filename or by id.. as in

videos.php?id=4
videos.php?id=jcartGoneWild
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

cool.

so to make my databaase, i will need to fields, one with autoincrement for the id? and another for the file name?
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

a sample db would be..

Code: Select all

id int not null auto_increment primary key
name varchar(50) /* general name of the file; you can even custom name the file or you do not need name at all */
Category varchar(50) /* You can have a separate table for categories and include category id here */
OtherIdentificationField varchar(50) /* singer / name of the album */
fileLocation varchar(100) /* Location of the media file can be anywhere; provided this to href of 'a' tag */
Description /* File description */
engine = myisam /* for full text search */
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

I just need 3 fields, i dont need it to be a monster DB with all of the info to put in.

I tried to make the table based on my knowledge, and what I thought
and this is the code for the table mySQL created for me

Code: Select all

SQL query: 
CREATE TABLE  `videos` (
 `ID` INT( 99 ) AUTO_INCREMENT ,
 `Name` BLOB,
 `Filename` BLOB,
PRIMARY KEY (  `ID` )
) TYPE = MYISAM ;
would that work?

EDIT: I changed Blob to text.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

you do not need either a blob or text...
you are not going to store massive information in it so use varchar(length) or use tinyblob if you need.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

ok so i will change it to that, how would i add the information, like rows?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

create a run-once script using glob() or opendir() and readdir() to capture all the filenames and insert them only into the db..

make sure you only run it once though :wink:
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

i only got like 10 videos so far, so i am just going to do it manually, easier for me.

any way. to add videos now, i am going to

1. Insert
2. Leaving ID blank (because it is auto_increment)
3. Typing in name and file name.


When I do that and insert videos and click browse, it looks just how I thought it would, good. lol.

Now How do I get it into a link and play it??

Again,

I want the video to be played on the same page.

So http://www.example.com/play.php?id=1 <-- I want that to play the video with the ID 1 in the database.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

What are you asking? How to you embed a video or how to get the information from the db?
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

I am trying to list files in a directory which match any one of the two extensions but the syntax does not work...I tried this from a snippet in PHP Manual..

Code: Select all

<pre>
<?php 
echo "Print php files:<br />"; print_r(glob("*.php"));
echo "Print php and xml files:<br />"; print_r(glob("*.php;*.xml"));
echo "Print all files:<br />"; print_r(glob("*.*"));
?>  
</pre>
output:

Code: Select all

Print php files:Array
(
    [0] => dbConnection.php
    [1] => phpinfo.php
    [2] => regex.php
    [3] => secondConnection.php
    [4] => timediff.php
    [5] => timer.php
)
Print php and xml files:Array
(
)
Print all files:Array
(
    [0] => dbConnection.php
    [1] => international.xml
    [2] => phpinfo.php
    [3] => regex.php
    [4] => secondConnection.php
    [5] => timediff.php
    [6] => timer.php
)
Post Reply