Instant track display on skip
This commit is contained in:
parent
8061119ecc
commit
6d2a707f42
@ -19,9 +19,10 @@
|
|||||||
overflow-y hidden
|
overflow-y hidden
|
||||||
border-radius 3px
|
border-radius 3px
|
||||||
opacity 0.75
|
opacity 0.75
|
||||||
|
transform opacity transition-speed ease
|
||||||
|
|
||||||
:hover
|
:hover
|
||||||
opacity 1
|
opacity 1 !important
|
||||||
|
|
||||||
#audio-player-anime-image
|
#audio-player-anime-image
|
||||||
width 100%
|
width 100%
|
||||||
|
@ -14,6 +14,7 @@ var trackLink = document.getElementById("audio-player-track-title") as HTMLLinkE
|
|||||||
var animeInfo = document.getElementById("audio-player-anime-info") as HTMLElement
|
var animeInfo = document.getElementById("audio-player-anime-info") as HTMLElement
|
||||||
var animeLink = document.getElementById("audio-player-anime-link") as HTMLLinkElement
|
var animeLink = document.getElementById("audio-player-anime-link") as HTMLLinkElement
|
||||||
var animeImage = document.getElementById("audio-player-anime-image") as HTMLImageElement
|
var animeImage = document.getElementById("audio-player-anime-image") as HTMLImageElement
|
||||||
|
var lastRequest: XMLHttpRequest
|
||||||
|
|
||||||
// Play audio
|
// Play audio
|
||||||
export function playAudio(arn: AnimeNotifier, element: HTMLElement) {
|
export function playAudio(arn: AnimeNotifier, element: HTMLElement) {
|
||||||
@ -31,6 +32,11 @@ function playAudioFile(arn: AnimeNotifier, trackId: string, trackUrl: string) {
|
|||||||
playId++
|
playId++
|
||||||
let currentPlayId = playId
|
let currentPlayId = playId
|
||||||
|
|
||||||
|
if(lastRequest) {
|
||||||
|
lastRequest.abort()
|
||||||
|
lastRequest = null
|
||||||
|
}
|
||||||
|
|
||||||
// Stop current track
|
// Stop current track
|
||||||
stopAudio(arn)
|
stopAudio(arn)
|
||||||
|
|
||||||
@ -38,23 +44,33 @@ function playAudioFile(arn: AnimeNotifier, trackId: string, trackUrl: string) {
|
|||||||
arn.markPlayingSoundTrack()
|
arn.markPlayingSoundTrack()
|
||||||
arn.loading(true)
|
arn.loading(true)
|
||||||
|
|
||||||
|
// Mark as loading
|
||||||
|
audioPlayer.classList.add("loading-network")
|
||||||
|
audioPlayer.classList.remove("decoding-audio")
|
||||||
|
audioPlayer.classList.remove("decoded")
|
||||||
|
|
||||||
// Request
|
// Request
|
||||||
let request = new XMLHttpRequest()
|
let request = new XMLHttpRequest()
|
||||||
request.open("GET", trackUrl, true)
|
request.open("GET", trackUrl, true)
|
||||||
request.responseType = "arraybuffer"
|
request.responseType = "arraybuffer"
|
||||||
|
|
||||||
request.onload = () => {
|
request.onload = () => {
|
||||||
arn.loading(false)
|
|
||||||
|
|
||||||
if(currentPlayId !== playId) {
|
if(currentPlayId !== playId) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mark as loading finished, now decoding starts
|
||||||
|
audioPlayer.classList.add("decoding-audio")
|
||||||
|
arn.loading(false)
|
||||||
|
|
||||||
audioContext.decodeAudioData(request.response, async buffer => {
|
audioContext.decodeAudioData(request.response, async buffer => {
|
||||||
if(currentPlayId !== playId) {
|
if(currentPlayId !== playId) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mark as ready
|
||||||
|
audioPlayer.classList.add("decoded")
|
||||||
|
|
||||||
audioNode = audioContext.createBufferSource()
|
audioNode = audioContext.createBufferSource()
|
||||||
audioNode.buffer = buffer
|
audioNode.buffer = buffer
|
||||||
audioNode.connect(gainNode)
|
audioNode.connect(gainNode)
|
||||||
@ -69,7 +85,27 @@ function playAudioFile(arn: AnimeNotifier, trackId: string, trackUrl: string) {
|
|||||||
playNextTrack(arn)
|
playNextTrack(arn)
|
||||||
// stopAudio(arn)
|
// stopAudio(arn)
|
||||||
}
|
}
|
||||||
|
}, console.error)
|
||||||
|
}
|
||||||
|
|
||||||
|
request.onerror = () => {
|
||||||
|
arn.loading(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
lastRequest = request
|
||||||
|
request.send()
|
||||||
|
|
||||||
|
// Update track info
|
||||||
|
updateTrackInfo(trackId)
|
||||||
|
|
||||||
|
// Show audio player
|
||||||
|
audioPlayer.classList.remove("fade-out")
|
||||||
|
audioPlayerPlay.classList.add("fade-out")
|
||||||
|
audioPlayerPause.classList.remove("fade-out")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update track info
|
||||||
|
async function updateTrackInfo(trackId: string) {
|
||||||
// Set track title
|
// Set track title
|
||||||
let trackInfoResponse = await fetch("/api/soundtrack/" + trackId)
|
let trackInfoResponse = await fetch("/api/soundtrack/" + trackId)
|
||||||
let track = await trackInfoResponse.json()
|
let track = await trackInfoResponse.json()
|
||||||
@ -96,19 +132,6 @@ function playAudioFile(arn: AnimeNotifier, trackId: string, trackUrl: string) {
|
|||||||
animeImage.classList.remove("hidden")
|
animeImage.classList.remove("hidden")
|
||||||
animeImage["became visible"]()
|
animeImage["became visible"]()
|
||||||
}
|
}
|
||||||
}, console.error)
|
|
||||||
}
|
|
||||||
|
|
||||||
request.onerror = () => {
|
|
||||||
arn.loading(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
request.send()
|
|
||||||
|
|
||||||
// Show audio player
|
|
||||||
audioPlayer.classList.remove("fade-out")
|
|
||||||
audioPlayerPlay.classList.add("fade-out")
|
|
||||||
audioPlayerPause.classList.remove("fade-out")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop audio
|
// Stop audio
|
||||||
@ -134,6 +157,10 @@ export function stopAudio(arn: AnimeNotifier) {
|
|||||||
animeInfo.classList.add("hidden")
|
animeInfo.classList.add("hidden")
|
||||||
animeImage.classList.add("hidden")
|
animeImage.classList.add("hidden")
|
||||||
|
|
||||||
|
// Show play button
|
||||||
|
audioPlayerPlay.classList.remove("fade-out")
|
||||||
|
audioPlayerPause.classList.add("fade-out")
|
||||||
|
|
||||||
if(gainNode) {
|
if(gainNode) {
|
||||||
gainNode.disconnect()
|
gainNode.disconnect()
|
||||||
}
|
}
|
||||||
@ -168,7 +195,7 @@ export async function playNextTrack(arn: AnimeNotifier) {
|
|||||||
let track = await response.json()
|
let track = await response.json()
|
||||||
|
|
||||||
playAudioFile(arn, track.id, "https://notify.moe/audio/" + track.file)
|
playAudioFile(arn, track.id, "https://notify.moe/audio/" + track.file)
|
||||||
arn.statusMessage.showInfo("Now playing: " + track.title)
|
// arn.statusMessage.showInfo("Now playing: " + track.title)
|
||||||
|
|
||||||
return track
|
return track
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user