473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

i need to play aauudio file

kamill
71
I need to play audio file in media player using PHP, how can i integrate it?
Jul 18 '07 #1
7 1531
pbmods
5,821 Expert 4TB
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.
Jul 18 '07 #2
tscott
22
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]
Jul 18 '07 #3
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...?
Jul 19 '07 #4
pbmods
5,821 Expert 4TB
Heya, suma.

See the previous posts in this thread.
Jul 19 '07 #5
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
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $dir = "song";
  3. $dh = opendir($dir) or die ("could not open dir");
  4. while ( !(($file = readdir($dh)) === false) ){
  5. if ($file == "." || $file == "..") continue;
  6. if (eregi(".mp3",$file)){
  7.  $sheets[] .= $file;echo'<br>';
  8. echo '<a href="' . playmusic($file) . '">' . $file . '</a>&nbsp; ';
  9. }
  10. }
  11. ?>
  12.  
  13.       <?php
  14.  
  15.       //Starting my function//
  16.  
  17.  
  18.  
  19.       function playmusic($music)
  20.  
  21.                   {
  22.  
  23.                          //Checking to see if it exists//
  24.  
  25.                           if(file_exists($music))
  26.  
  27.                                  {
  28.  
  29.                                        //Showing the music in the user's player//
  30.  
  31.                                        echo '<embed src=' . $music . '></embed>';
  32.  
  33.                                   }
  34.  
  35.                                 else
  36.  
  37.                                  {
  38.  
  39.                                          //If it does not exist it will go here//
  40.  
  41.                                          echo 'The music file you selected does not exist';
  42.  
  43.                                  }
  44.  
  45.                   }
  46.  
  47.       ?>
  48.  
Jul 20 '07 #6
pbmods
5,821 Expert 4TB
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.
Jul 20 '07 #7
tscott
22
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>&nbsp;<BR>';

}
}
if($music == 'true')
{
$file = $_GET['file'];
echo '<embed src="'. $dir . '/' . $file . '"></embed>';
}

?>[/php]
Jul 20 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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. ...
1
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. ...
1
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...
1
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"...
1
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...
13
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,...
20
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...
8
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...
1
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...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
0
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...
0
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...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
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....
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.