I need to play audio file in media player using PHP, how can i integrate it?
7 1531
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($music)
{
//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]
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...?
Heya, suma.
See the previous posts in this thread.
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 -
<?
-
$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($music)
-
-
{
-
-
//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';
-
-
}
-
-
}
-
-
?>
-
Heya, sumaabey.
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
You don't need the playmusic() function at all. The while loop at the top does all the work for you.
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=true&file=' . $file . '">' . $file . '</a> <BR>';
}
}
if($music == 'true')
{
$file = $_GET['file'];
echo '<embed src="'. $dir . '/' . $file . '"></embed>';
}
?>[/php]
Sign in to post your reply or Sign up for a free account.
Similar topics
by: cbell |
last post by:
I would like javascript file (which can be a .js file) which I can use
to play .wav files on demand. there are many pages and there will only
be ONE .wav file (about 20 seconds) for each page.
...
|
by: Ron Provost |
last post by:
Hello,
I'm developing a piece of software to assist illiteraate adults to learn to
read. I'm trying to figure out how, if possible, to make audio playback
asynchrnous but still controllable. ...
|
by: Lord2702 |
last post by:
I want to play a sound file, which is on my server, and approximately 5 - 7
MB it is .Wav file. or .mp3, I want to play this file so that user of my
site can click on a link to play this file. Is...
|
by: Lam |
last post by:
how can I play sound file in a .aspx page written in C#?
I try to use the code like the following. But whenI call the play function
play("sound.wav", this.SND_ASYNC)
my computer give out "be"...
|
by: Jerry Spence1 |
last post by:
I am building an application and I require some media player buttons (play,
record, fast forward etc). They won't be controlling standard audio though.
There doesn't seem to be a set with VB.Net so...
|
by: anil.rita |
last post by:
When the user chooses an AV file to play, based upon the type of file,
I want to use the default installed media player to play it.
I am wondering if this is a good way - any alternatives,...
|
by: mike |
last post by:
I help manage a large web site, one that has over
600 html pages... It's a reference site for ham radio
folks and as an example, one page indexes over
1.8 gb of on-line PDF documents.
The site...
|
by: raylopez99 |
last post by:
I have the latest version of Visual Studio 2008 Professional, which
allows you to create resource files (this is the .resx file, no?),
unlike the Express version, which does not.
I am trying to...
|
by: rockchicx23 |
last post by:
i have to write a program that is a guessing the number game. the user has to choose the number of games they want to play. i need help setting up the loop that will run the number of times the user...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |