Unable to obtain songs in Library playlist
Thank you for your efforts. I used the following code to request the playlists and albums in the Library, but the returned data did not include songs. For example: Tracks in the Playlist project is empty.
` let playlist = try await MLibrary.playlist(id: MusicItemID(rawValue: id))
print(playlist.tracks) <-
`
Thank you again!
Hi there! Thank you for using MusadoraKit! 🥳
Apple Music usually keeps the response lean, especially for library data. That may be the reason for the tracks being nil.
Here is how you can get the tracks for a playlist:
let playlist = try await MLibrary.playlist(id: "p.kmURBma9pE").with(.tracks)
Hi there! Thank you for using MusadoraKit! 🥳
Apple Music usually keeps the response lean, especially for library data. That may be the reason for the tracks being
nil.Here is how you can get the tracks for a playlist:
let playlist = try await MLibrary.playlist(id: "p.kmURBma9pE").with(.tracks)
Thanks for the tip, now it works. In recent use, I also found:
The songs in the library returned using code like the following are always empty:
let response = try await MLibrary.songs() <---- Empty
That's interesting. I tried it right now, and it works well. What is the iOS version you tested on? Under the hood, it is using MusicLibraryRequest<Song> for iOS 16.0+
var request = MusicLibraryRequest<Song>()
request.limit = limit
let response = try await request.response()
return response.items
That's interesting. I tried it right now, and it works well. What is the iOS version you tested on? Under the hood, it is using
MusicLibraryRequest<Song>for iOS 16.0+var request = MusicLibraryRequest<Song>() request.limit = limit let response = try await request.response() return response.items
That's interesting. I tried it right now, and it works well. What is the iOS version you tested on? Under the hood, it is using
MusicLibraryRequest<Song>for iOS 16.0+var request = MusicLibraryRequest<Song>() request.limit = limit let response = try await request.response() return response.items
I spent some time checking, but can't solve it so far. I think it may be that I don't know much about the powerful MusadoraKit, and I must take the time to understand this powerful library.
However, I obtained the songs through other methods of MusadoraKit's MLIbrary, such as:
let librarySongs = try await MLibrary.songsForAlbums().flatMap { $0.items }
This gets the music items in the library normally, and then I sort them by the time they were added, so this is a compromise. 😄
In addition, I found that when I run MusadoraKit's sample SwiftUI project into my device, I can get the music from the library normally. I will now take a look at the specific logic of the sample project.
Sorry I didn't provide my running environment.
iOS 17.41, ipadOS 17.41, tvOS 17.4
Compiled by Xcode 15.3. MusadoraKit version: 4.2.0
Thank you for providing such a powerful library, if I discover additional information in the future, I will report it immediately.
Wish you all the best.
That is indeed weird if the Musadora app is working fine, here is the code:
struct LibrarySongsView: View {
@State private var songs: Songs = []
var body: some View {
SongsView(with: songs)
.navigationTitle("Songs")
.task {
do {
songs = try await MLibrary.songs()
} catch {
print(error)
}
}
}
}