mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-29 06:37:16 +02:00
Fix:Changing track sort order (Android) #380
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
package com.audiobookshelf.app.data
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||||
|
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
data class AudioTrack(
|
||||||
|
var index:Int,
|
||||||
|
var startOffset:Double,
|
||||||
|
var duration:Double,
|
||||||
|
var title:String,
|
||||||
|
var contentUrl:String,
|
||||||
|
var mimeType:String,
|
||||||
|
var metadata:FileMetadata?,
|
||||||
|
var isLocal:Boolean,
|
||||||
|
var localFileId:String?,
|
||||||
|
var audioProbeResult:AudioProbeResult?,
|
||||||
|
var serverIndex:Int? // Need to know if server track index is different
|
||||||
|
) {
|
||||||
|
|
||||||
|
@get:JsonIgnore
|
||||||
|
val startOffsetMs get() = (startOffset * 1000L).toLong()
|
||||||
|
@get:JsonIgnore
|
||||||
|
val durationMs get() = (duration * 1000L).toLong()
|
||||||
|
@get:JsonIgnore
|
||||||
|
val endOffsetMs get() = startOffsetMs + durationMs
|
||||||
|
@get:JsonIgnore
|
||||||
|
val relPath get() = metadata?.relPath ?: ""
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
fun getBookChapter():BookChapter {
|
||||||
|
return BookChapter(index + 1,startOffset, startOffset + duration, title)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -122,10 +122,13 @@ class Book(
|
|||||||
override fun setAudioTracks(audioTracks:MutableList<AudioTrack>) {
|
override fun setAudioTracks(audioTracks:MutableList<AudioTrack>) {
|
||||||
tracks = audioTracks
|
tracks = audioTracks
|
||||||
tracks?.sortBy { it.index }
|
tracks?.sortBy { it.index }
|
||||||
// TODO: Is it necessary to calculate this each time? check if can remove safely
|
|
||||||
var totalDuration = 0.0
|
var totalDuration = 0.0
|
||||||
|
var currentStartOffset = 0.0
|
||||||
tracks?.forEach {
|
tracks?.forEach {
|
||||||
totalDuration += it.duration
|
totalDuration += it.duration
|
||||||
|
it.startOffset = currentStartOffset
|
||||||
|
currentStartOffset += it.duration
|
||||||
}
|
}
|
||||||
duration = totalDuration
|
duration = totalDuration
|
||||||
}
|
}
|
||||||
@@ -158,7 +161,6 @@ class Book(
|
|||||||
}
|
}
|
||||||
duration = totalDuration
|
duration = totalDuration
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
override fun getLocalCopy(): Book {
|
override fun getLocalCopy(): Book {
|
||||||
return Book(metadata as BookMetadata,coverPath,tags, mutableListOf(),chapters,mutableListOf(),null,null, 0)
|
return Book(metadata as BookMetadata,coverPath,tags, mutableListOf(),chapters,mutableListOf(),null,null, 0)
|
||||||
@@ -329,36 +331,6 @@ data class Folder(
|
|||||||
var fullPath:String
|
var fullPath:String
|
||||||
)
|
)
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
||||||
data class AudioTrack(
|
|
||||||
var index:Int,
|
|
||||||
var startOffset:Double,
|
|
||||||
var duration:Double,
|
|
||||||
var title:String,
|
|
||||||
var contentUrl:String,
|
|
||||||
var mimeType:String,
|
|
||||||
var metadata:FileMetadata?,
|
|
||||||
var isLocal:Boolean,
|
|
||||||
var localFileId:String?,
|
|
||||||
var audioProbeResult:AudioProbeResult?,
|
|
||||||
var serverIndex:Int? // Need to know if server track index is different
|
|
||||||
) {
|
|
||||||
|
|
||||||
@get:JsonIgnore
|
|
||||||
val startOffsetMs get() = (startOffset * 1000L).toLong()
|
|
||||||
@get:JsonIgnore
|
|
||||||
val durationMs get() = (duration * 1000L).toLong()
|
|
||||||
@get:JsonIgnore
|
|
||||||
val endOffsetMs get() = startOffsetMs + durationMs
|
|
||||||
@get:JsonIgnore
|
|
||||||
val relPath get() = metadata?.relPath ?: ""
|
|
||||||
|
|
||||||
@JsonIgnore
|
|
||||||
fun getBookChapter():BookChapter {
|
|
||||||
return BookChapter(index + 1,startOffset, startOffset + duration, title)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
data class BookChapter(
|
data class BookChapter(
|
||||||
var id:Int,
|
var id:Int,
|
||||||
|
|||||||
+1
-1
@@ -358,7 +358,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||||||
customActionProviders.addAll(listOf(
|
customActionProviders.addAll(listOf(
|
||||||
SkipBackwardCustomActionProvider(),
|
SkipBackwardCustomActionProvider(),
|
||||||
SkipForwardCustomActionProvider(),
|
SkipForwardCustomActionProvider(),
|
||||||
));
|
))
|
||||||
}
|
}
|
||||||
mediaSessionConnector.setCustomActionProviders(*customActionProviders.toTypedArray());
|
mediaSessionConnector.setCustomActionProviders(*customActionProviders.toTypedArray());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user