mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-07-12 06:54:50 +02:00
Begin handling playback of local media
This commit is contained in:
parent
76de92fe1f
commit
0b46a9c9b1
5 changed files with 95 additions and 20 deletions
|
@ -58,6 +58,53 @@ extension LocalLibraryItem {
|
|||
self.serverAddress = server.address
|
||||
self.serverUserId = server.userId
|
||||
}
|
||||
|
||||
func getDuration() -> Double {
|
||||
var total = 0.0
|
||||
self.media?.tracks.forEach { track in total += track.duration }
|
||||
return total
|
||||
}
|
||||
|
||||
func getPlaybackSession(episode: LocalPodcastEpisode?) -> PlaybackSession {
|
||||
let localEpisodeId = episode?.id
|
||||
let sessionId = "play_local_\(UUID().uuidString)"
|
||||
|
||||
// Get current progress from local media
|
||||
let mediaProgressId = (localEpisodeId != nil) ? "\(self.id)-\(localEpisodeId!)" : self.id
|
||||
let mediaProgress = Database.shared.getLocalMediaProgress(localMediaProgressId: mediaProgressId)
|
||||
|
||||
// TODO: Clean up add mediaType methods for displayTitle and displayAuthor
|
||||
let mediaMetadata = self.media?.metadata
|
||||
let audioTracks = self.media?.tracks
|
||||
let authorName = mediaMetadata?.authorName
|
||||
|
||||
if let episode = episode {
|
||||
// TODO: Implement podcast
|
||||
}
|
||||
|
||||
let dateNow = Date().timeIntervalSince1970
|
||||
return PlaybackSession(
|
||||
id: sessionId,
|
||||
userId: self.serverUserId,
|
||||
libraryItemId: self.libraryItemId,
|
||||
episodeId: episode?.serverEpisodeId,
|
||||
mediaType: self.mediaType,
|
||||
chapters: [],
|
||||
displayTitle: mediaMetadata?.title,
|
||||
displayAuthor: authorName,
|
||||
coverPath: nil,
|
||||
duration: self.getDuration(),
|
||||
playMethod: 3,
|
||||
startedAt: dateNow,
|
||||
updatedAt: 0,
|
||||
timeListening: 0.0,
|
||||
audioTracks: [],
|
||||
currentTime: mediaProgress?.currentTime ?? 0.0,
|
||||
libraryItem: nil,
|
||||
serverConnectionConfigId: self.serverConnectionConfigId,
|
||||
serverAddress: self.serverAddress
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
extension LocalMediaType {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue