I need to play audio file in media player using PHP, how can i integrate it?
i need to play aauudio file
Collapse
X
-
Heya, kamill.
PHP doesn't work that way, unless you want your SERVER playing the audio file (which would be kind of funny if the server had a speaker, and the guy at the server farm was working the overnight shift for the past three nights).
If you want to play the audio file in the User's browser, either link to the audio file directly, or else use an OBJECT tag to incorporate it into your HTML. -
Here's a function to help you out :)
[php]
<?php
//Starting my function//
function playmusic($musi c)
{
//Checking to see if it exists//
if(file_exists( $music))
{
//Showing the music in the user's player//
echo '<embed src=' . $music . '></embed>';
}
else
{
//If it does not exist it will go here//
echo 'The music file you selected does not exist';
}
}
?>
[/php]Comment
-
hai suma here...thanks
$dir = "song";
$dh = opendir($dir) or die ("could not open dir");
while ( !(($file = readdir($dh)) === false) ){
if ($file == "." || $file == "..") continue;
if (eregi(".mp3",$ file)){
$sheets[] .= $file;
}
}
by using this code i can fetch the mp3 file from the song folder.Now how to play this...?Comment
-
Hi pbmods
WHY this error?Is this is the way to play audiofile.The code is pasted below
Error is
The music file you selected does not existtrack1.mp3
The music file you selected does not existtrack2.mp3
The music file you selected does not existtrack3.mp3
[code=php]
<?
$dir = "song";
$dh = opendir($dir) or die ("could not open dir");
while ( !(($file = readdir($dh)) === false) ){
if ($file == "." || $file == "..") continue;
if (eregi(".mp3",$ file)){
$sheets[] .= $file;echo'<br> ';
echo '<a href="' . playmusic($file ) . '">' . $file . '</a> ';
}
}
?>
<?php
//Starting my function//
function playmusic($musi c)
{
//Checking to see if it exists//
if(file_exists( $music))
{
//Showing the music in the user's player//
echo '<embed src=' . $music . '></embed>';
}
else
{
//If it does not exist it will go here//
echo 'The music file you selected does not exist';
}
}
?>
[/code]Comment
-
Heya, sumaabey.
Originally posted by sumaabeyHi pbmods
WHY this error?Is this is the way to play audiofile.The code is pasted below
Error is
The music file you selected does not existtrack1.mp3
The music file you selected does not existtrack2.mp3
The music file you selected does not existtrack3.mp3Comment
-
That would only echo a link to it and not actually play the music though. To do what you want you'd need this.
Example Here : See Example
[php]
<?
$dir ="songs";
$dh = opendir($dir);
while ( !(($file = readdir($dh)) === false) )
{
if ($file == "." || $file == "..") continue;
if (eregi(".mp3",$ file))
{
echo '<a href="?music=tr ue&file=' . $file . '">' . $file . '</a> <BR>';
}
}
if($music == 'true')
{
$file = $_GET['file'];
echo '<embed src="'. $dir . '/' . $file . '"></embed>';
}
?>[/php]Comment
Comment