PDA

View Full Version : PHP Script to play media files from a web directory



Fli
04-17-2014, 03:27 PM
Hi, im looking for the script that will enable me to play media files like avi mp4 mp3 in certain web directory and its subdirectories.
Do you know any such?




I found JW Player which supports mp4, m4v, f4v, mov, flv, webm, aac, m4a, f4a, mp3, ogg, oga


This is script to create playlist out of a local web folder and load JW player to play it.


Example:
100



cd /your/www/directory
mkdir media
cd media
vi index.php


paste:

<?php
$path = "./files/";
$path2="http://".$_SERVER['SERVER_NAME'].dirname($_SERVER["PHP_SELF"])."/files/";
//echo $path2;
$folder = opendir($path);
$start="<asx version='3.0'>\n<title>Example ASX playlist</title>";
$Fnm = "./playlist.xml";
$inF = fopen($Fnm,"w");
fwrite($inF,$start."\n");
while( $file = readdir($folder) ) {
if (($file != '.')&&($file != '..')&&($file != 'index.htm')){
$result="<entry>\n<title>$file</title>\n<ref href='$path2$file'/>\n<param name='image' value='preview.jpg'/>\n</entry>\n";
fwrite($inF,$result);
}
}
fwrite($inF,"</asx>");
closedir($folder);
fclose($inF);
?>
<html>
<head>
<title>player</title>
</head>
<body>
<center>
<br/><br/>
<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='470' height='470' id='single1' name='single1'>
<param name='movie' value='player.swf'>
<param name='allowfullscreen' value='true'>
<param name='allowscriptaccess' value='always'>
<param name='wmode' value='transparent'>
<param name='flashvars' value='playlistfile=playlist.xml&image=preview.jpg&playlist=bottom'>
<embed
type='application/x-shockwave-flash'
id='single2'
name='single2'
src='player.swf'
width='470'
height='470'
bgcolor='undefined'
allowscriptaccess='always'
allowfullscreen='true'
wmode='transparent'
flashvars='playlistfile=playlist.xml&image=preview.jpg&playlist=bottom'
/>
</object>
<br/><br/>
Download videos: (right clic + save as)<br/><br/>
<?php
$dir = opendir("./files");
while($file = readdir($dir)) {
if(($file == "index.htm") || ($file == ".") || ($file == "..")){} else {
echo


"<a title='".$file."' href='".$path.$file."'>".$file."</a><br/>";
}
}


closedir($dir);
?>
<br/>
</center>
</body>
</html>



touch playlist.xml;chmod 777 playlist.xml


download "JW Player" package from internet, example: http://www.porse.cz/JW_Player/download.html
extract it and it should contain player.swf and preview.jpg


copy these into your /your/www/directory/media


so you have index.php, playlist.xml, player.swf and preview.jpg in your media www folder, now create folder for your audio and video:



mkdir files
(should be named as files, else you need to edit index.php)


if you want this web audio/video player all in one, you can download this whole file and extract it into your wanted www directory:
101

jonray76
02-24-2015, 07:22 AM
any possible way to get someone to make a quick doc on how to do this for a website I run for our church? We have the pastor uploading his files to a folder on the server and I would like to have a page that viewers can go to and hear the songs with player and not have to edit the HTML to add each file each time. I can explain further if someone can help me. THANKS IN ADVANCE!

Fli
03-03-2015, 12:41 PM
jonray76, try to download file i attached to mi first post (player.zip (http://internetlifeforum.com/attachments/php-mysql-forum/attachment-101d1397748620-php-script-play-media-files-web-directory-player.zip/)) and extract it on your webserver. After extracting, you should have a folder called "player" and inside is this:
195
add your media to the folder "files" and open index.php in web browser. If that dont work, i will try to fix/find solution.