61 lines
1.4 KiB
TypeScript
Raw Permalink 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) {
2019-11-17 09:25:14 +00:00
const {mediaId, audioSrc} = element.dataset
2019-04-22 06:02:51 +00:00
if(!mediaId || !audioSrc) {
console.error("Invalid media ID or audio source:", element)
return
}
arn.audioPlayer.play(mediaId, 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) {
2019-11-17 09:25:14 +00:00
const volume = parseFloat(element.value) / 100.0
2018-03-24 22:04:31 +00:00
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.
2018-12-07 00:54:17 +00:00
if(arn.currentMediaId && element.dataset.mediaId === arn.currentMediaId) {
2018-03-24 22:04:31 +00:00
stopAudio(arn)
} else {
playAudio(arn, element)
2018-03-11 03:45:01 +00:00
}
2018-03-16 16:03:59 +00:00
}