54 lines
1.3 KiB
TypeScript
Raw Normal View History

2018-04-02 05:34:16 +00:00
import AnimeNotifier from "../AnimeNotifier"
2018-03-11 02:00:06 +00:00
2018-03-11 19:22:33 +00:00
// Play audio
2018-03-11 14:43:17 +00:00
export function playAudio(arn: AnimeNotifier, element: HTMLElement) {
2018-03-24 22:04:31 +00:00
arn.audioPlayer.play(element.dataset.soundtrackId, element.dataset.audioSrc)
2018-03-11 19:22:33 +00:00
}
2018-03-24 22:04:31 +00:00
// Pause audio
2018-11-16 07:46:56 +00:00
export function pauseAudio(arn: AnimeNotifier) {
2018-03-24 22:04:31 +00:00
arn.audioPlayer.pause()
2018-03-11 03:45:01 +00:00
}
2018-03-24 22:04:31 +00:00
// Resume audio
2018-11-16 07:46:56 +00:00
export function resumeAudio(arn: AnimeNotifier) {
2018-03-24 22:04:31 +00:00
arn.audioPlayer.resume()
2018-03-12 19:21:22 +00:00
}
2018-03-11 14:43:17 +00:00
// Stop audio
export function stopAudio(arn: AnimeNotifier) {
2018-03-24 22:04:31 +00:00
arn.audioPlayer.stop()
2018-03-16 16:03:59 +00:00
}
2018-03-11 20:37:07 +00:00
// Play previous track
export async function playPreviousTrack(arn: AnimeNotifier) {
2018-03-24 22:04:31 +00:00
arn.audioPlayer.previous()
2018-03-11 20:37:07 +00:00
}
2018-03-11 19:22:33 +00:00
// Play next track
export async function playNextTrack(arn: AnimeNotifier) {
2018-03-24 22:04:31 +00:00
arn.audioPlayer.next()
2018-03-11 19:22:33 +00:00
}
2018-03-11 16:20:52 +00:00
// Set volume
2018-03-11 17:17:35 +00:00
export function setVolume(arn: AnimeNotifier, element: HTMLInputElement) {
2018-03-24 22:04:31 +00:00
let volume = parseFloat(element.value) / 100.0
arn.audioPlayer.setVolume(volume)
2018-03-11 16:20:52 +00:00
}
2018-03-24 22:04:31 +00:00
// Play or pause audio
export function playPauseAudio(arn: AnimeNotifier) {
arn.audioPlayer.playPause()
2018-03-11 03:45:01 +00:00
}
2018-03-24 22:04:31 +00: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 03:45:01 +00:00
}
2018-03-16 16:03:59 +00:00
}