Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flo/PlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct PlayerView: View {
.padding(.bottom, 5)

ScrollView {
VStack(alignment: .leading) {
LazyVStack(alignment: .leading) {
ForEach(viewModel.queue.indices, id: \.self) { idx in
HStack(alignment: .top) {
VStack(alignment: .leading) {
Expand Down
31 changes: 16 additions & 15 deletions flo/Shared/Services/PlaybackService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,24 @@ class PlaybackService {
func addToQueue<T: Playable>(item: T, isFromLocal: Bool = false) -> [QueueEntity] {
self.clearQueue()

for song in item.songs {
let queue = QueueEntity(context: CoreDataManager.shared.viewContext)

queue.id = song.mediaFileId == "" ? song.id : song.mediaFileId
queue.albumId = song.albumId
queue.albumName = item.name
queue.artistName = song.artist
queue.bitRate = Int16(song.bitRate)
queue.sampleRate = Int32(song.sampleRate)
queue.songName = song.title
queue.suffix = song.suffix
queue.isFromLocal = isFromLocal
queue.duration = song.duration

CoreDataManager.shared.saveRecord()
let objects = item.songs.map { song in
return [
"id": song.mediaFileId == "" ? song.id : song.mediaFileId,
"albumId": song.albumId,
"albumName": item.name,
"artistName": song.artist,
"bitRate": song.bitRate,
"sampleRate": song.sampleRate,
"songName": song.title,
"suffix": song.suffix,
"isFromLocal": isFromLocal,
"duration": song.duration
] as [String : Any]
}

let request = NSBatchInsertRequest(entity: QueueEntity.entity(), objects: objects)
_ = try? CoreDataManager.shared.viewContext.execute(request)

return self.getQueue()
}
}