From d7dce6502074eda12d149330be661b1b0dd3b65f Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sun, 11 Mar 2018 21:37:07 +0100 Subject: [PATCH] Added skip button --- layout/sidebar/audioplayer.pixy | 4 ++-- scripts/Actions/Audio.ts | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/layout/sidebar/audioplayer.pixy b/layout/sidebar/audioplayer.pixy index f4678352..6ed12167 100644 --- a/layout/sidebar/audioplayer.pixy +++ b/layout/sidebar/audioplayer.pixy @@ -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") \ No newline at end of file diff --git a/scripts/Actions/Audio.ts b/scripts/Actions/Audio.ts index 735e388b..1d8c627e 100644 --- a/scripts/Actions/Audio.ts +++ b/scripts/Actions/Audio.ts @@ -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 }