eshaz / icecast-metadata-js

Browser and NodeJS packages for playing and reading Icecast compatible streaming audio with realtime metadata updates.
155 stars 20 forks source link

Existing audio html element #92

Closed fabioricali closed 2 years ago

fabioricali commented 2 years ago

Hi,

is there any way to attach an existing audio html element to your component? So you have a metadataChange event? Without using IcecastMetadataStats...

eshaz commented 2 years ago

Yes, you can pass in the reference to your audio element into the audioElement parameter of the options object when creating a new IcecastMetadataPlayer. See this section of the readme for more information on this.

For your second question, you can use the onMetadata callback, or onmetadata event if you prefer, to capture each metadata update. See this link. To track if there was a change you will need to write your own logic to check if the new metadata is actually different than the previous update.

The IcecastMetadataStats library is intended to be used only if you need the stream metadata without playing the audio. It can be configured to poll your icecast compatible server for metadata at a given interval without playing the stream. You will still need to write the logic to track for changes, and updates will only happen as fast as the polling frequency you configure.

fabioricali commented 2 years ago

Hi eshaz,

thank you for your reply. I already have a player in my case it is Clappr. So what I was asking you was if it was possible to hook your lib to an html5 media element like that of my player so as not to pool with IcecastMetadataStats and then take advantage of the event of your lib onMetadata... this would save me a lot of requests on the servers without upsetting the whole project. I also use Clappr for video streams so it would be difficult for me to switch to your player.

eshaz commented 2 years ago

Unfortunately, that's not possible to do. When the HTTP request is being made internally by the Audio element, there's no way to access the actual request data. There are a couple of ways around this, but that's the majority of the icecast-metadata-player library.

I briefly looked at Clappr, and you might be able to write a plugin that uses icecast-metadata-js, but that would probably be a large effort, and there's no guarantee that Clappr provides the right interface to send raw compressed audio data for playback.