Web [Open-Source] Random Music (RM)

Discussion in 'Source Code & Tutorial Database' started by Rellfer, May 21, 2015 with 8 replies and 615 views.

  1. Rellfer

    Rellfer Enthusiast

    Messages:
    39
    Ratings:
    15
    Hello!

    I made this simple JS code that plays a random music from an array. It shows the music name, and it also has the link to download the music.

    If you want to test it, click here.

    [Click here to view the link]

    Here is the base JS code:



    And here the base HTML:


    The good thing about this is that people can discover new songs and already download them \o/
     
    • Like Like x 1
    Last edited: Jun 3, 2015
  2. Mr Smithy x

    Mr Smithy x Enthusiast

    Messages:
    328
    Ratings:
    180
  3. Xeren

    Xeren ♦♦♦ God Complex ♦♦♦

    Messages:
    5,678
    Ratings:
    1,890
    You should make the "playing" function dynamic so you wouldn't have to continuously add to it every time you want to add a song.
     
  4. OP
    Rellfer

    Rellfer Enthusiast

    Messages:
    39
    Ratings:
    15
    Yes, but that's the only way if the musics are like: 1.mp3, 2.mp3, euoheuiewq.mp3 (not my case)

    A good way to do that would be like:



    I didn't test it, but I think it works fine.

    Thanks for the alert anyway! :smile:
     
  5. Im4eversmart

    Im4eversmart The hacks are real

    Messages:
    2,098
    Ratings:
    1,669
    You could also host a file containing all resources definitions, such as file name and title. If you store it in json format, you can easily read it right into a js var. This would allow you to create dynamic code, and still be able to print out the song title or other information.

    This is how Pandora does their Api.
     
  6. OP
    Rellfer

    Rellfer Enthusiast

    Messages:
    39
    Ratings:
    15
    Important Edit

    Now it refreshes the page when the song ends, so it's like a web radio :smile:

    What I've changed:

    Code:
    document.write('<EMBED src= "'+ soundFile +'" hidden=true autostart=true loop=true>');
    
    to

    Code:
    document.write ('<audio hidden="true" id="player" controls autoplay><source src="' + soundFile + '" type="audio/mp3" /></audio>');
    
    And add at the end of the code:

    Code:
    $("#player").bind('ended', function(){
        location.reload();
    });
    
    Test it here

    OBS: It uses jQuery
     
  7. CallingChain

    CallingChain Enthusiast

    Messages:
    170
    Ratings:
    51
    This is pretty cool.
    How exactly does it download it?

    It generate a link itself?[DOUBLEPOST=1433292635][/DOUBLEPOST]Also,
    You should add a player so you can contol the actions.

    The site has a modern design.
    Try releasing this script on GitHub :smile:
     
    • Like Like x 1
  8. OP
    Rellfer

    Rellfer Enthusiast

    Messages:
    39
    Ratings:
    15
    I always forget about my github account :speechless:
    I will upload it in there with everything working, then it will be easier to use/edit.

    About the controls, I just don't put them because I wanted to simulate a webradio, but maybe a sound level controller would be nice :smile:

    [Click here to view the link]

    Thanks
     
    • Like Like x 1
    Last edited: Jun 3, 2015
  9. CallingChain

    CallingChain Enthusiast

    Messages:
    170
    Ratings:
    51
    You're Welcome.
    I used it on PS4 and nothing played so that's where that suggestion came in :smile:
     

Share This Page