serversideup / amplitudejs

AmplitudeJS: Open Source HTML5 Web Audio Library. Design your web audio player, the way you want. No dependencies required.
https://521dimensions.com/open-source/amplitudejs
MIT License
4.18k stars 427 forks source link

Set method for active track? (eg. Live Stream where the song title changes) #274

Closed Kezzsim closed 6 years ago

Kezzsim commented 6 years ago

Greetings~

I've been using Amplitudejs for a while now to write a silent disco app, which is hopefully nearing completion. The premise works with icecast/shoutcast streams and then distributes them to clients who use amplitude to play back the content.

I'm using sockets to shuttle some things back and forth, and I can parse a bunch of stream metadata on the server side to then send over to the client to update accordingly. Right now the only way I know how to set anything with amplitude is to call the init function, but that would cause two instances of the stream to exist and take control of one player away from the user.

Are there any methods like Amplitude.setSongName or something that can hot swap metadata so when the song name changes and a new request comes in from the server, it can update accordingly? I know that in the meantime I can just engage in further DOM manipulation by selecting the song-name class and changing it's attributes, but I think it would be more elegant to actually update the object so I can call it elsewhere if needed.

Thanks for developing this, looking forward to finding out more about it~

Question Checklist

danpastori commented 6 years ago

Hi @Kezzsim ,

Awesome idea for an app and thanks for using AmplitudeJS. Right now there is not a method to do this, but I will work on adding one here shortly. I like the idea and hope to have this done this weekend. I'll respond to this thread and you can send a link.

danpastori commented 6 years ago

Hi @Kezzsim If you use the dev branch: https://github.com/521dimensions/amplitudejs/tree/dev I have a method called Amplitude.setMetaData(index, metaData) which accepts the index of the song you are updating and an array of meta data. This way if you want to update only the title, you'd pass:

Amplitude.setMetaData(0, {'title': 'YOUR UPDATED TITLE'}); 

You can pass as many updates as you want such as artist, title, album, etc. Or any other new meta data if you want. It will sync with the screen for any element that references that song index. Let me know how this works for you. The only field you can not update is the URL because that'd cause issues if the song is being played.