Currently working on integrating an audio player into my Angular web application by following a tutorial from Google Developers and seeking guidance from a thread on Can't seek video when playing from MediaSource.
The unique aspect of my implementation is that I aim to stream audio in small chunks so users can listen without having to download the entire file initially.
The functionality of starting playback from the beginning using byte-chunks appended to SourceBuffer upon arrival is already functional.
However, I am encountering difficulties with implementing the "seek" feature.
I'm unsure about handling this on the client side, specifically for mp3 files. Information on how the seeking
event works has been elusive.
It's known that setting the currentTime
of an audio
element triggers a seeking
event based on the Media Events documentation.
this.audioObj = document.createElement('audio');
and also including a setter:
public seekTo(seconds) {
this.logger.debug(`seekTo ${seconds.toFixed(2)} seconds`);
// Setting currentTime will cause a "seeking" event to be emitted.
this.audioObj.currentTime = seconds;
}
My understanding suggests that new data must be loaded before setting currentTime
and appending it to the sourceBuffer
, although this approach seems flawed.
Seeking advice on making this function as intended.