iosswiftapple-musickit

Swift - open the music app and play specific album


I'm having problems with finding out information or a documentation on how to open the music app with a specific album and playing it.

The closest I found right now is

        let url = URL(string: "music://")
    UIApplication.shared.open(url!, options: [:], completionHandler: nil)

I've tried a few combinations with the path and options but no luck, it always just opens the app and does nothing beyond that.

I initially thought this would open through the MPMediaPlayer but that just plays it in the app and is now what I need.


Solution

  • You want the MPMusicPlayerController systemMusicPlayer.

    https://developer.apple.com/documentation/mediaplayer/mpmusicplayercontroller

    It is the Music app.