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 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2009
    Posts
    84
    Thanks
    3
    Thanked 0 Times in 0 Posts

    How to make random play?

    Here is the code I have that will play in both IE and FF:

    <embed name="playlist"
    src="/MUSIC/playlist.m3u"
    type="application/x-mplayer2"
    width="300"
    height="90"
    loop="true"
    hidden="false"
    autostart="true"
    shuffle="true" <--adding this didn't work
    </embed>

    How can I make it play random instead of the first song listed in the playlist?

  • #2
    New Coder
    Join Date
    Jan 2009
    Posts
    84
    Thanks
    3
    Thanked 0 Times in 0 Posts
    found this. He said needed to make php file. I'd tried but didn't work.

    <?php
    $playlist = "/home/sites/myname/www.example.com/examples/playlist.m3u";
    if ($_SERVER['PATH_INFO'] == "/playlist.m3u") {
    # This a request for the actual playlist.
    playlist();
    } else {
    # Fall through to end of script and display
    # the player HTML.
    }
    function playlist() {
    header("Content-type: audio/mpeg");

    # Needed for PHP versions OLDER than 4.2.0 only.
    # If your host still has PHP older than 4.2.0, shame on them.
    # Find a better web host.
    srand(make_seed());

    # Fetch our list of songs from a file.
    $songs = file($playlist);
    shuffle($songs);
    # Now output the URLs in random order.
    foreach ($songs as $song) {
    # Remove newline and any other leading and trailing
    # whitespace from URL of song.
    $song = trim($song);
    echo "$song\n";
    }
    # Now exit before any HTML is produced.
    exit(0);
    }
    # Needed only for very old versions of PHP,
    # see srand call earlier.
    function make_seed()
    {
    list($usec, $sec) = explode(' ', microtime());
    return (float) $sec + ((float) $usec * 100000);
    }
    ?>

    <html>
    <head>
    <title>MP3s Playing in Random Order</title>
    </head>
    <body>
    <h1 align="center">MP3s Playing in Random Order</h1>
    <embed src="/examples/randomsongs.php/playlist.m3u"
    width="0"
    height="0"
    autostart="true"
    type="audio/mpeg"
    loop="true"/>
    </body>
    </html>


    Not sure if i can post the link on here, i'll need to go back and read the "read me before postin"


  •  

    Posting Permissions

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