mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-05 04:51:09 +01:00
Fix:Mark media as finished if less than 5 seconds remain on a sync and call progress sync again when last track ends #635
This commit is contained in:
parent
6161daeef0
commit
93b8e11378
@ -52,12 +52,12 @@ export default class CastPlayer extends EventEmitter {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// var currentItemId = media.currentItemId
|
|
||||||
var currentItemId = media.media.itemId
|
var currentItemId = media.media.itemId
|
||||||
if (currentItemId && this.currentTrackIndex !== currentItemId - 1) {
|
if (currentItemId && this.currentTrackIndex !== currentItemId - 1) {
|
||||||
this.currentTrackIndex = currentItemId - 1
|
this.currentTrackIndex = currentItemId - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Emit finished event
|
||||||
if (media.playerState !== this.castPlayerState) {
|
if (media.playerState !== this.castPlayerState) {
|
||||||
this.emit('stateChange', media.playerState)
|
this.emit('stateChange', media.playerState)
|
||||||
this.castPlayerState = media.playerState
|
this.castPlayerState = media.playerState
|
||||||
|
@ -76,6 +76,7 @@ export default class LocalPlayer extends EventEmitter {
|
|||||||
this.loadCurrentTrack()
|
this.loadCurrentTrack()
|
||||||
} else {
|
} else {
|
||||||
console.log(`[LocalPlayer] Ended`)
|
console.log(`[LocalPlayer] Ended`)
|
||||||
|
this.emit('finished')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
evtError(error) {
|
evtError(error) {
|
||||||
|
@ -101,6 +101,7 @@ export default class PlayerHandler {
|
|||||||
this.player.on('timeupdate', this.playerTimeupdate.bind(this))
|
this.player.on('timeupdate', this.playerTimeupdate.bind(this))
|
||||||
this.player.on('buffertimeUpdate', this.playerBufferTimeUpdate.bind(this))
|
this.player.on('buffertimeUpdate', this.playerBufferTimeUpdate.bind(this))
|
||||||
this.player.on('error', this.playerError.bind(this))
|
this.player.on('error', this.playerError.bind(this))
|
||||||
|
this.player.on('finished', this.playerFinished.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
playerError() {
|
playerError() {
|
||||||
@ -111,6 +112,16 @@ export default class PlayerHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
playerFinished() {
|
||||||
|
this.stopPlayInterval()
|
||||||
|
|
||||||
|
var currentTime = this.player.getCurrentTime()
|
||||||
|
this.ctx.setCurrentTime(currentTime)
|
||||||
|
|
||||||
|
// TODO: Add listening time between last sync and now?
|
||||||
|
this.sendProgressSync(currentTime)
|
||||||
|
}
|
||||||
|
|
||||||
playerStateChange(state) {
|
playerStateChange(state) {
|
||||||
console.log('[PlayerHandler] Player state change', state)
|
console.log('[PlayerHandler] Player state change', state)
|
||||||
this.playerState = state
|
this.playerState = state
|
||||||
|
@ -173,9 +173,6 @@ class Server {
|
|||||||
// Metadata folder static path
|
// Metadata folder static path
|
||||||
app.use('/metadata', this.authMiddleware.bind(this), express.static(global.MetadataPath))
|
app.use('/metadata', this.authMiddleware.bind(this), express.static(global.MetadataPath))
|
||||||
|
|
||||||
// TODO: Are these necessary?
|
|
||||||
// Downloads folder static path
|
|
||||||
// app.use('/downloads', this.authMiddleware.bind(this), express.static(this.downloadManager.downloadDirPath))
|
|
||||||
// Static folder
|
// Static folder
|
||||||
app.use(express.static(Path.join(global.appRoot, 'static')))
|
app.use(express.static(Path.join(global.appRoot, 'static')))
|
||||||
|
|
||||||
@ -212,7 +209,7 @@ class Server {
|
|||||||
const dyanimicRoutes = [
|
const dyanimicRoutes = [
|
||||||
'/item/:id',
|
'/item/:id',
|
||||||
'/item/:id/manage',
|
'/item/:id/manage',
|
||||||
'/item/:id/chapters',
|
'/audiobook/:id/chapters',
|
||||||
'/audiobook/:id/edit',
|
'/audiobook/:id/edit',
|
||||||
'/library/:library',
|
'/library/:library',
|
||||||
'/library/:library/search',
|
'/library/:library/search',
|
||||||
@ -220,6 +217,7 @@ class Server {
|
|||||||
'/library/:library/authors',
|
'/library/:library/authors',
|
||||||
'/library/:library/series/:id?',
|
'/library/:library/series/:id?',
|
||||||
'/config/users/:id',
|
'/config/users/:id',
|
||||||
|
'/config/users/:id/sessions',
|
||||||
'/collection/:id'
|
'/collection/:id'
|
||||||
]
|
]
|
||||||
dyanimicRoutes.forEach((route) => app.get(route, (req, res) => res.sendFile(Path.join(distPath, 'index.html'))))
|
dyanimicRoutes.forEach((route) => app.get(route, (req, res) => res.sendFile(Path.join(distPath, 'index.html'))))
|
||||||
|
@ -89,7 +89,9 @@ class MediaProgress {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.progress >= 1 && !this.isFinished) {
|
var timeRemaining = this.duration - this.currentTime
|
||||||
|
// If time remaining is less than 5 seconds then mark as finished
|
||||||
|
if ((this.progress >= 1 || (!isNaN(timeRemaining) && timeRemaining < 5)) && !this.isFinished) {
|
||||||
this.isFinished = true
|
this.isFinished = true
|
||||||
this.finishedAt = Date.now()
|
this.finishedAt = Date.now()
|
||||||
this.progress = 1
|
this.progress = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user