Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2013
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    php detect when file is finshed scan again

    I've been browsing this forum for a while and decided to jump in now.

    I have a script which scans a directory for mp3's and serves them in a html5 audio player. It works very well except when the audio file is finished that's it it just finishes. The user would now have to manually reload the page to get another random audio file.

    So here's what I want the script to do:
    When page loads, load a random mp3 from the folder. (Solved)

    Render that mp3 link into a html5 audio player (solved)

    At the end of the song play another mp3( not solved)

    Here's my current code:

    PHP Code:
     <!DOCTYPE html>
    <html lang="en">
        <head>
            

      
    <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, user-scalable=yes, minimum-scale=1.0">
            <title>And your phone number is...</title>
            <style>
                body {
                    font: 17px sans-serif;
                    color: #444;
                    margin: 20px;
                }
                        </style>
        </head>


        <body>


    <?php
    $dir 
    '../cod2/'
    $scan scandir($dir);
    $size sizeof($scan);
    $random rand(1$size);
    $randomFile $scan[$random];
    $fileLocation $dir$randomFile;
    $explode explode("."$randomFile);
    $extension $explode[1]
    ?>


             

    <center><h3>Song Picture Here</h3>


    <audio controls>
        <source src="<?php echo $fileLocation?>" type="audio/mpeg">
        <source src="<?php echo $fileLocation?>" type="audio/ogg">

    preload="auto" ></audio>


        
        
    <center>




    <h3>
    <?php echo $randomFile;?>
    </h3></center>

    <p>More info here</p>
    </body>
    </HTML>

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,281
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    I don't think you're going to control your player with php. PHP only deals with html text manipulation, files, databases, filestreams etc. It doesn't actively change properties of a webpage being viewed in a browser.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    New Coder
    Join Date
    Mar 2013
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    So what do you suggest? I'm not well in other languages
    .

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,281
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    Well I'd suggest you get 'well' in javascript
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Yep, use a combination of both JS and PHP. Scan the directory for all the files, and provide that to the JS.
    So effectively, that is this:
    PHP Code:
    $dir '../cod2/'
    $scan scandir($dir); 
    All done fetching the directory here. Now, you need to give that to JS. My JS skills are ahhh, antiquated (pre-dom antiquated), but PHP does have a function called json_encode which allows you to convert an array in PHP to that of a json array. That should help you get started with the data in the JS, for which you can then choose (iteratively, shuffle it, randomize it, etc) with the JS, and change it up. I don't know how to hook it into the HTML5 audio though to determine when it finished playing; for that you'll want to check with the client side developers for an event handle of some sorts.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •