i need to play aauudio file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kamill
    New Member
    • Dec 2006
    • 71

    i need to play aauudio file

    I need to play audio file in media player using PHP, how can i integrate it?
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    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.

    Comment

    • tscott
      New Member
      • Jul 2007
      • 22

      #3
      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]
      Last edited by tscott; Jul 18 '07, 11:49 PM. Reason: making it not so wide (obsessed with tabbing)

      Comment

      • sumaabey
        New Member
        • Jun 2007
        • 29

        #4
        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

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, suma.

          See the previous posts in this thread.

          Comment

          • sumaabey
            New Member
            • Jun 2007
            • 29

            #6
            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>&nbsp; ';
            }
            }
            ?>

            <?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

            • pbmods
              Recognized Expert Expert
              • Apr 2007
              • 5821

              #7
              Heya, sumaabey.

              Originally posted by 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.

              Comment

              • tscott
                New Member
                • Jul 2007
                • 22

                #8
                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>&nbsp;<BR>';

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

                ?>[/php]
                Last edited by tscott; Jul 20 '07, 11:02 PM. Reason: fixing it.

                Comment

                Working...