method playSegment(startTime, endTime)
bebekar opened this issue · comments
Bebekar commented
playSegment could facilitate playing any segment of the audio. It could also have events such as onEnded.
Alexander Heimbuch commented
In general this is not the kind of functionality that belongs into this lib. The reason is that it should be as stateless as possible, start and end time tracking will introduce a hook registry that needs to be called every time a specific playtime was reached. Still this is something you could easily implement yourself:
import { curry } from 'ramda'
import { audio } from 'html5-audio-driver'
import { onPlaytimeUpdate } from 'html5-audio-driver/events'
import { play, pause, setPlaytime } from 'html5-audio-driver/actions'
const audioElement = audio([{
url: 'audio-files/example.m4a',
mimeType: 'audio/mp4'
}, {
url: 'audio-files/example.mp3',
mimeType: 'audio/mp3'
}, {
url: 'audio-files/example.ogg',
mimeType: 'audio/ogg'
}])
const playSegment = curry((media, start, stop) => {
onPlaytimeUpdate(media, playtime => {
if (playtime > stop) {
pause()
}
})
setPlaytime(media, start)
play(media)
})
playSegment(audioElement, 50, 200)
Hope that helps :)
Bebekar commented
Thanks