54 lines
1.4 KiB
TypeScript
Raw Normal View History

2018-04-02 07:34:16 +02:00
import AnimeNotifier from "../AnimeNotifier"
2018-03-11 03:00:06 +01:00
2018-03-11 20:22:33 +01:00
// Play audio
2018-03-11 15:43:17 +01:00
export function playAudio(arn: AnimeNotifier, element: HTMLElement) {
2018-03-24 23:04:31 +01:00
arn.audioPlayer.play(element.dataset.soundtrackId, element.dataset.audioSrc)
2018-03-11 20:22:33 +01:00
}
2018-03-24 23:04:31 +01:00
// Pause audio
export function pauseAudio(arn: AnimeNotifier, button: HTMLButtonElement) {
arn.audioPlayer.pause()
2018-03-11 04:45:01 +01:00
}
2018-03-24 23:04:31 +01:00
// Resume audio
export function resumeAudio(arn: AnimeNotifier, button: HTMLButtonElement) {
arn.audioPlayer.resume()
2018-03-12 20:21:22 +01:00
}
2018-03-11 15:43:17 +01:00
// Stop audio
export function stopAudio(arn: AnimeNotifier) {
2018-03-24 23:04:31 +01:00
arn.audioPlayer.stop()
2018-03-16 17:03:59 +01:00
}
2018-03-11 21:37:07 +01:00
// Play previous track
export async function playPreviousTrack(arn: AnimeNotifier) {
2018-03-24 23:04:31 +01:00
arn.audioPlayer.previous()
2018-03-11 21:37:07 +01:00
}
2018-03-11 20:22:33 +01:00
// Play next track
export async function playNextTrack(arn: AnimeNotifier) {
2018-03-24 23:04:31 +01:00
arn.audioPlayer.next()
2018-03-11 20:22:33 +01:00
}
2018-03-11 17:20:52 +01:00
// Set volume
2018-03-11 18:17:35 +01:00
export function setVolume(arn: AnimeNotifier, element: HTMLInputElement) {
2018-03-24 23:04:31 +01:00
let volume = parseFloat(element.value) / 100.0
arn.audioPlayer.setVolume(volume)
2018-03-11 17:20:52 +01:00
}
2018-03-24 23:04:31 +01:00
// Play or pause audio
export function playPauseAudio(arn: AnimeNotifier) {
arn.audioPlayer.playPause()
2018-03-11 04:45:01 +01:00
}
2018-03-24 23:04:31 +01:00
// Toggle audio
export function toggleAudio(arn: AnimeNotifier, element: HTMLElement) {
// If we're clicking on the same track again, stop playing.
// Otherwise, start the track we clicked on.
if(arn.currentSoundTrackId && element.dataset.soundtrackId === arn.currentSoundTrackId) {
stopAudio(arn)
} else {
playAudio(arn, element)
2018-03-11 04:45:01 +01:00
}
2018-03-16 17:03:59 +01:00
}