Added skip button

This commit is contained in:
Eduard Urbach 2018-03-11 21:37:07 +01:00
parent 220549b30b
commit d7dce65020
2 changed files with 17 additions and 5 deletions

View File

@ -1,7 +1,7 @@
component AudioPlayer
#audio-player
#audio-player-controls
button#audio-player-prev.audio-player-side-button
button#audio-player-prev.audio-player-side-button.action(data-action="playPreviousTrack", data-trigger="click")
RawIcon("step-backward")
.audio-player-play-pause-container
@ -11,7 +11,7 @@ component AudioPlayer
button#audio-player-pause.fade-out.action(data-action="pauseAudio", data-trigger="click")
RawIcon("pause")
button#audio-player-next.audio-player-side-button
button#audio-player-next.audio-player-side-button.action(data-action="playNextTrack", data-trigger="click")
RawIcon("step-forward")
input#audio-player-volume.action(data-action="setVolume", data-trigger="input", type="range", min="0", max="100", value="50")

View File

@ -30,6 +30,7 @@ function playAudioFile(arn: AnimeNotifier, trackId: string, trackUrl: string) {
arn.currentSoundTrackId = trackId
arn.markPlayingSoundTrack()
arn.loading(true)
// Request
let request = new XMLHttpRequest()
@ -37,6 +38,8 @@ function playAudioFile(arn: AnimeNotifier, trackId: string, trackUrl: string) {
request.responseType = "arraybuffer"
request.onload = () => {
arn.loading(false)
if(currentPlayId !== playId) {
return
}
@ -63,6 +66,10 @@ function playAudioFile(arn: AnimeNotifier, trackId: string, trackUrl: string) {
}, console.error)
}
request.onerror = () => {
arn.loading(false)
}
request.send()
// Show audio player
@ -107,6 +114,11 @@ export function toggleAudio(arn: AnimeNotifier, element: HTMLElement) {
}
}
// Play previous track
export async function playPreviousTrack(arn: AnimeNotifier) {
alert("Previous track is currently work in progress! Check back later :)")
}
// Play next track
export async function playNextTrack(arn: AnimeNotifier) {
// Get random track
@ -114,6 +126,7 @@ export async function playNextTrack(arn: AnimeNotifier) {
let track = await response.json()
playAudioFile(arn, track.id, "https://notify.moe/audio/" + track.file)
arn.statusMessage.showInfo("Now playing: " + track.title)
return track
}
@ -140,10 +153,9 @@ export function pauseAudio(arn: AnimeNotifier, button: HTMLButtonElement) {
}
// Resume audio
export async function resumeAudio(arn: AnimeNotifier, button: HTMLButtonElement) {
export function resumeAudio(arn: AnimeNotifier, button: HTMLButtonElement) {
if(!audioNode) {
let track = await playNextTrack(arn)
arn.statusMessage.showInfo("Now playing: " + track.title)
playNextTrack(arn)
return
}