0

I've got a folder containing several *.mp3 files. Now what I'm trying to achieve is, that these mp3s are played on my webpage continously meaning that if I close my browser and open the page i.e. 10 seconds later again, the song should continue 10 seconds after I left.

It also should play the same file for every client connected. (So pretty much like a web-radio)

But how could one do that most efficient? I made a little sample project, which is increasing a value on a database every second, and if the value is larger than the playtime of the mp3, it will change the active mp3.

Same goes for the client, every second I check if the mp3 has changed and if so i change the src of the audio tag.

But I beleive this is not really efficient. Does anyone have any ideas on how to decrease the ressources used?

Thanks in advance.

Lumnezia
  • 796
  • 2
  • 9
  • 32

1 Answers1

1

If you don't care about actually retaining the playback information cross-browser/platform for a user, you could just utilize a local storage solution to keep track of the song and current placement, then use a client-side JavaScript solution to check this value and play the song at the appropriate time without having to include a database call for the lookup.

Or if cross-platform is a requirement, you could at least store it locally and try to resolve that first and if there isn't a cached record for the song, then fall back to the database lookup.

Whit Waldo
  • 4,806
  • 4
  • 48
  • 70