What's new

Web [Open-Source] Random Music (RM)

Rellfer

Rellfer

Enthusiast
Messages
39
Reaction score
16
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 this 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/
 
Last edited:
Xeren

Xeren

♦♦♦ God Complex ♦♦♦
Legendary Veteran Programmer Modder
Messages
5,671
Reaction score
2,105
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.
 
Rellfer

Rellfer

Enthusiast
Messages
39
Reaction score
16
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.

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:
 
Im4eversmart

Im4eversmart

The hacks are real
Glitcher Modder Programmer
Messages
2,161
Reaction score
1,903
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:

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.
 
Rellfer

Rellfer

Enthusiast
Messages
39
Reaction score
16
Important Edit

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

What I've changed:

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

to

JavaScript:
document.write ('<audio hidden="true" id="player" controls autoplay><source src="' + soundFile + '" type="audio/mp3" /></audio>');

And add at the end of the code:

JavaScript:
$("#player").bind('ended', function(){
    location.reload();
});

Test it here

OBS: It uses jQuery
 
CallingChain

CallingChain

Enthusiast
Messages
170
Reaction score
54
This is pretty cool.
How exactly does it download it?

It generate a link itself? 
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:
 
Rellfer

Rellfer

Enthusiast
Messages
39
Reaction score
16
This is pretty cool.
How exactly does it download it?

It generate a link itself? 
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:

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 this link]

Thanks
 
Last edited:
CallingChain

CallingChain

Enthusiast
Messages
170
Reaction score
54
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 this link]

Thanks

You're Welcome.
I used it on PS4 and nothing played so that's where that suggestion came in :smile:
 
Top Bottom