mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-04 18:15:01 +02:00
Working local file playback
This commit is contained in:
parent
65fcc45bc6
commit
9477860bca
6 changed files with 74 additions and 24 deletions
|
@ -90,6 +90,8 @@ struct Metadata: Realmable, Codable {
|
|||
var seriesName: String?
|
||||
var feedUrl: String?
|
||||
|
||||
var authorDisplayName: String { self.authorName ?? "Unknown" }
|
||||
|
||||
init() {
|
||||
title = "Unknown"
|
||||
genres = []
|
||||
|
@ -251,6 +253,11 @@ struct AudioTrack: Realmable, Codable {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func getLocalFile() -> LocalFile? {
|
||||
guard let localFileId = self.localFileId else { return nil }
|
||||
return Database.shared.getLocalFile(localFileId: localFileId)
|
||||
}
|
||||
}
|
||||
|
||||
struct FileMetadata: Realmable, Codable {
|
||||
|
|
|
@ -59,6 +59,12 @@ extension LocalLibraryItem {
|
|||
return total
|
||||
}
|
||||
|
||||
func getPodcastEpisode(episodeId: String?) -> PodcastEpisode? {
|
||||
guard self.isPodcast else { return nil }
|
||||
guard let episodes = self.media?.episodes else { return nil }
|
||||
return episodes.first(where: { $0.id == episodeId })
|
||||
}
|
||||
|
||||
func getPlaybackSession(episode: PodcastEpisode?) -> PlaybackSession {
|
||||
let localEpisodeId = episode?.id
|
||||
let sessionId = "play_local_\(UUID().uuidString)"
|
||||
|
@ -67,13 +73,13 @@ extension LocalLibraryItem {
|
|||
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
|
||||
let chapters = self.media?.chapters
|
||||
var audioTracks = self.media?.tracks
|
||||
let authorName = mediaMetadata?.authorDisplayName
|
||||
|
||||
if let episode = episode {
|
||||
// TODO: Implement podcast
|
||||
if let episode = episode, let track = episode.audioTrack {
|
||||
audioTracks = [track]
|
||||
}
|
||||
|
||||
let dateNow = Date().timeIntervalSince1970
|
||||
|
@ -81,18 +87,18 @@ extension LocalLibraryItem {
|
|||
id: sessionId,
|
||||
userId: self.serverUserId,
|
||||
libraryItemId: self.libraryItemId,
|
||||
episodeId: episode?.id,
|
||||
episodeId: episode?.serverEpisodeId,
|
||||
mediaType: self.mediaType,
|
||||
chapters: [],
|
||||
chapters: chapters ?? [],
|
||||
displayTitle: mediaMetadata?.title,
|
||||
displayAuthor: authorName,
|
||||
coverPath: nil,
|
||||
coverPath: self.coverContentUrl,
|
||||
duration: self.getDuration(),
|
||||
playMethod: 3,
|
||||
playMethod: PlayMethod.local.rawValue,
|
||||
startedAt: dateNow,
|
||||
updatedAt: 0,
|
||||
timeListening: 0.0,
|
||||
audioTracks: [],
|
||||
audioTracks: audioTracks ?? [],
|
||||
currentTime: mediaProgress?.currentTime ?? 0.0,
|
||||
libraryItem: nil,
|
||||
serverConnectionConfigId: self.serverConnectionConfigId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue