Post not yet marked as solved
The new MusicLibraryRequest<Playlist>() is great to get all the user's playlists but I have not found a way to exclude a specific type of playlist. For example; I wish to only get playlists that the user owns and can add content to (so this would exclude Smart and Curated playlists)
I did find the Playlist.Kind enum, but I can't seem to apply this to the request, and it doesn't seem to have an option for smart playlists.
So in short:
Is there any way I can exclude Smart- and Curated Playlists from a MusicLibraryRequest
Post not yet marked as solved
I'm developing an app which utilises playback from the Apple Music catalogue using MusicKit. Playback works fine however, whenever the playback state changes the ApplicationMusicPlayer.shared.state.objectWillChange publisher is fired twice. Moreover, with each emit the ApplicationMusicPlayer.shared.state is different.
An example:
Music is playing in my app.
Music is paused. (Through any method of pausing)
The objectWillChange publisher is called twice.
In first call state is .playing
In the second call state is .paused
The same happens if playback is then resumed except the states switch. First, .paused and then .playing.
I'm using Combine's .sink() method. I've checked for accidental duplicate subscriptions but there is only one. Is this the intended behaviour or is this an issue?
Post not yet marked as solved
Specifically, when the song is cut in the background, or when we open our APP after cutting the song through the music APP, the song cover built with ArtworkImage does not have any display, why is this?
I have ensured that the artwork of the song is not nil and set the size,
here is my application code:
public func updateUI() {
coverImgView.subviews.forEach { $0.removeFromSuperview() }
let imageView = PlayerCoverImageView(artwork: artwork, size: size)
let viewCtl = UIHostingController(rootView: imageView)
viewCtl.view.frame = coverImgView.bounds
viewCtl.view.backgroundColor = .clear
coverImgView.addSubview(viewCtl.view)
}
@available(iOS 15.0, *)
struct PlayerCoverImageView: View {
var artwork: Artwork?
var size: CGSize
var body: some View {
if let artwork = artwork {
createCover(with: artwork)
} else {
EmptyView()
}
}
private func createCover(with artwork: Artwork) -> some View {
print("[*******] \(artwork), \(size)")
let width = size.width; let height = size.height
return ArtworkImage(artwork, width: width,
height: height)
}
}
console output:
Artwork(
urlFormat: "musicKit://artwork/library/56D232E0-6CE5-40B5-92C3-CFEEC00D9CA6/{w}x{h}?at=item&mt=music&fat=https://is4-ssl.mzstatic.com/image/thumb/Music115/v4/45/8a/e4/458ae484-dc8b-5683-ce04-8d2948346462/JAY.jpg/1125x1229bb.jpg&id=6762479945777034135&fas=subscription&lid=56D232E0-6CE5-40B5-92C3-CFEEC00D9CA6",
maximumWidth: 0,
maximumHeight: 0
)
(307.0, 307.0)
Post not yet marked as solved
Hi.
I'm trying out some of the new MusicKit functionality using Xcode 14 beta 3 and macOS 13 beta 3 and I'm getting the above error (or similar) whenever I use any of the new classes with a Mac Catalyst destination (an iOS 16 destination works fine).
I'm guessing one of my build settings is incorrect on either my project or target, but it's not obvious. So far I've set:
Project / IOS Deployment Target = 16.0
Target / Minimum Deployments / iOS = 16.0
Could someone please tell me what I'm missing?
Thanks in advance!
Post not yet marked as solved
Hello, am trying to use musickit.
Am Curious, since am only interesting in musickit api web, dose that mean i will have to pay for developers' fees ?
Post not yet marked as solved
In this thread it has been stated that getting artist artwork through the MusicKit api isn't allowed because of copyright issues. My question is:
Is using the Apple Music REST api to get album artwork via the OpenGraph API also disallowed such that my app would be rejected? Wonder if I should pursue this option that I found or if I need to find another way? Seems like the answer would be no, but wanted to double check.
Thanks for your response, this is my first app that I'm trying to publish to the store and I'd like to avoid getting an instant rejection for something like this.
Code snippet:
import MusicKit
import Foundation
import OpenGraph
extension Artist {
func artwork(width: Int = 1024, height: Int = 1024) async -> URL? {
let id = self.id.rawValue
let countryCode = try? await MusicDataRequest.currentCountryCode
let url = URL(string: "https://music.apple.com/\(countryCode ?? "us")/artist/\(id)")!
return await withCheckedContinuation { continuation in
OpenGraph.fetch(url: url) { result in
switch result {
case .success(let og):
let image = og[.image]?.resizeArtwork(width: width, height: height)
if let image = image, let url = URL(string: image) {
continuation.resume(returning: url)
} else {
continuation.resume(returning: nil)
}
case .failure(_):
continuation.resume(returning: nil)
}
}
}
}
}
extension String {
func resizeArtwork(width: Int, height: Int) -> String? {
do {
let regex = try NSRegularExpression(pattern: "/\\d+x\\d+cw", options: .caseInsensitive)
let newImage = regex.stringByReplacingMatches(in: self, options: [], range: NSRange(0..<self.utf16.count), withTemplate: "/\(width)x\(height)cc")
return newImage
} catch {
return nil
}
}
}
Post not yet marked as solved
I understand why there isn’t an API to remove items from the library or playlist, but I propose a way to safely remove items from the library or playlist which would show a system alert to confirm the removal. This is exactly how the deletion is allowed for the Photos Library via third-party apps.
Post not yet marked as solved
MusicPlayer.State supports shuffleMode and repeatMode, but there is no way to enable Autoplay.
In the case of SystemMusicPlayer a user can enable AutoPlay from iOS Music app, but for ApplicationMusicPlayer, there's no way to offer Autoplay support.
Additionally, when setting a new queue iOS Music app, disables Autoplay mode even if it was enabled before, but when using iOS Music app, the Autoplay stays enabled. I can understand that it may be intentional for some reason but doesn't seem user-friendly. Due to this, even when playing from Shortcuts app, Autoplay gets disabled, even though in most cases it shouldn't.
Post not yet marked as solved
When working with embedded web content inside a native app, any calls to MusicKit.authorize will not be properly authenticate.
Calling authenticate will open Safari, allow the user to login, then ask for user confirmation, but the window will not navigate back to the native app.
Is it expected that developers would have to enable associated domains for the native app?
Post not yet marked as solved
Anyway we can get the source code for this app to see the MusicKit functionality used in it?
Post not yet marked as solved
Android Music SDK Authentication always shows Install AppMusic App even though AppMusic App is already installed!
when targetSdkVersion 29 works fine and shows links to Apple Music but using
targetSdkVersion 30 always shows Install AppMusic App even though AppMusic App is already installed!
Apple developer, please check this problem
device : Pixel 6
Android os version : 12
Post not yet marked as solved
Hello!
I am currently working on a react.js application that is integrating with the MusicKit v3 library. I have followed the documentation to generate a JWT for MusicKit and add the library to my application.
Using my token I am able to successfully retrieve song information from the Apple Music API, but I am having trouble with authentication.
When I call music.authorize() and successfully go through the Apple sign in popup, I am receiving the following 403 error:
https://play.itunes.apple.com/WebObjects/MZPlay.woa/wa/webPlayerLogout 403 musickit.js:44 Uncaught (in promise) AUTHORIZATION_ERROR: Unauthorized
After stepping through the music kit API and login popup with breakpoints, I am seeing that the music user token is null, despite the login popup succeeding and returning a proper token/response:
{"isAppleMusicSubscriber":"true","musicUserToken":"Ak4ItOgRRRG2y6xgA/OeWQPK0RqPQ/esAJkRN0B/Ua/AWLT52tLhd2TfzMK6uhH+Nczvd7wjYDM1UewG/NledKtimwlrR+s5tdQPk/FG28zqhBqXZ12q6LC516w8ELZDwv5T61kV8xiJ1KSO1q4pGi01JO7SuPMtOqB/QsycYj+xNnrYUEwlP5tm/zxfg7bWmvuWMwfUruYR+A1U9FdXZsdIITVmxCjiHg8ro9xXRzl6Txhsag\u003d\u003d","cid":"REDACTED","itre":"REDACTED","supported":"REDACTED"}
I have tested my application with multiple Apple Music users who have paid subscriptions. All accounts are receiving this same error.
I have tried regenerating my JWT token multiple times following various guides. My latest attempt used the following node library and parameters:
var jwt = require('jsonwebtoken');
var fs = require('fs');
var privateKey = fs.readFileSync('./AuthKey_MYKEY.p8');
let now = new Date();
let nextMonth = new Date(now.getFullYear(), now.getMonth() + 1, now.getDate());
let nowEpoch = Math.round(now.getTime() / 1000); // number of seconds since Epoch, in UTC
let nextMonthEpoch = Math.round(nextMonth.getTime() / 1000); // number of seconds since Epoch, in UTC
var payload = {
iss: 'REDACTED', // TEAM ID
iat: nowEpoch,
exp: nextMonthEpoch
};
var options = {
algorithm: 'ES256',
header: {
alg: 'ES256',
kid: 'REDACTED' // KEY ID
}
};
jwt.sign(payload, privateKey, options, function(error, token) {
console.log(error);
console.log(token);
});
I have a valid App Identifier created with the MusicKit App Service enabled.
I am stuck! I have no other ideas on the possible root cause here. Is there something I am missing? I have a mobile app currently in Test Flight - does this app need to be released to the app store? I am out of guesses!
Any support here would be greatly appreciated!
Thank you for your time.
Patrick
Post not yet marked as solved
The supported Relationship Views for Albums in the API include appears-on, other-versions, related-albums, related-videos, but it doesn't support more-by-artist, this data is available when viewing the album in the Apple Music app and would be very useful if it was available in the Apple Music API and possibly MusicKit as well with new iOS update.
Post not yet marked as solved
Is it possible to play songs/playlists on another device on the same account of the user.
Effectively, remote control.
ex: I own a Mac Book and an iPad, my iPad is connected to speakers, I want to stop and start playing music on the iPad using my Mac Book, through APIs.
Post not yet marked as solved
Is there a way to use the MusicLibraryRequest to get the users loved songs, playlists, albums and artists? I don't see a way in documentation but maybe I am missing it.
Thanks,
Dan
Hi,
I'm trying out the beta for music kit. In the current version of my app, my widget can show multiple albums. I preload the images of the album covers. In the beta's the url that is returned for the artwork starts with: "musickit://", which does not work with URLSession. How can I preload the data using the new url scheme?
Current code:
func fetchArtworkFor (musicID: MusicItemID, url : URL?) async throws -> UIImage? {
guard let url = url else {
return nil
}
let urlRequest = URLRequest (url: url)
let data = try await URLSession.shared.data(for: urlRequest)
let image = UIImage(data: data.0)
return image
}
// Some other function
for album in albumsToShow {
if let url = album.artwork?.url(width: context.family.imageHeight, height: context.family.imageHeight), let image = try? await fetchArtworkFor(musicID: album.id, url:url) {
images[album] = image
}
}
Post not yet marked as solved
Hi I am working on a music app where I can do some sound analysis, my end goal is to integrate Apple Music API in my app where users can search songs. When the song is played I want to show a type of soundwave/spectrogram. For sound visualization I have AVFoundation but the Music API returns only song ID which could be played using Apple MediaPlayer framework only. Is there any API for doing sound analysis or can I play the Apple music songs using AVFoundation.
Post not yet marked as solved
Hi there!
I have been trying to play the music videos we get from Apple Music API and have been unsuccessful.
Here's my code:
var video: MusicVideo
var body: some View {
VideoPlayer(player: AVPlayer(url: video.url!))
}
I know the URL from the MusicVideo is not in a music format but just the URL to the video in the Apple Music catalog.
How do I go about playing it without using something like MPMusicPlayerController.systemMusicPlayer.openToPlay(queueDescriptor) and provide an in-app experience (and not take the user to the Apple Music app)?
Hi ,
I have a usecase where I need to add multiple songs to apple music playlists. I am using MPMediaplaylist.addItem(withProductID: ) function to add a single song to the playlist. Is there a way to convert the song to MPMediaItem so that I can use MPMediaplaylist.add([MPMediaItem]) to add multiple songs to the playlist?
Regards
When attempting to authenticate with the musickit-js v3, the page that gets loaded from authorize.music.apple.com results in an error "Cannot parse response"
On the desktop, this does not happen.
The authentication code in question is
async login() {
const mkInst = MusicKit.getInstance();
await mkInst.authorize();
}
Not sure if this is limited to V3, as it's technically not officially released, but figured it was worth bringing to attention.