61 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) {
2019-11-17 18:25:14 +09:00
const {mediaId, audioSrc} = element.dataset
2019-04-22 15:02:51 +09:00
if(!mediaId || !audioSrc) {
console.error("Invalid media ID or audio source:", element)
return
}
arn.audioPlayer.play(mediaId, audioSrc)
2018-03-11 20:22:33 +01:00
}
2018-03-24 23:04:31 +01:00
// Pause audio
2018-11-16 16:46:56 +09:00
export function pauseAudio(arn: AnimeNotifier) {
2018-03-24 23:04:31 +01:00
arn.audioPlayer.pause()
2018-03-11 04:45:01 +01:00
}
2018-03-24 23:04:31 +01:00
// Resume audio
2018-11-16 16:46:56 +09:00
export function resumeAudio(arn: AnimeNotifier) {
2018-03-24 23:04:31 +01:00
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) {
2019-11-17 18:25:14 +09:00
const volume = parseFloat(element.value) / 100.0
2018-03-24 23:04:31 +01:00
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.
2018-12-07 09:54:17 +09:00
if(arn.currentMediaId && element.dataset.mediaId === arn.currentMediaId) {
2018-03-24 23:04:31 +01:00
stopAudio(arn)
} else {
playAudio(arn, element)
2018-03-11 04:45:01 +01:00
}
2018-03-16 17:03:59 +01:00
}