Introducing MusicKit. Media #WWDC17. Tim Parthemore, MusicKit Services Joel Lopes Da Silva, ios Music

Similar documents
What s New in watchos

Media and Gaming Accessibility

Getting and Using a MapKit JS Key

What s New in Xcode App Signing

Mastering Drag and Drop

What s New in CloudKit

Enabling Your App for CarPlay

Introducing Password AutoFill for Apps

Data Delivery with Drag and Drop

Content Protection for HTTP Live Streaming

Introduction to Siri Shortcuts

What s New in tvos #WWDC16. App Frameworks. Session 206. Hans Kim tvos Engineer

Seamless Linking to Your App

Building Watch Apps #WWDC15. Featured. Session 108. Neil Desai watchos Engineer

Enhancing your apps for the next dimension of touch

What s New in Core Data?

WatchKit In-Depth, Part 2

Automatic Strong Passwords and Security Code AutoFill

What s New in Audio. Media #WWDC17. Akshatha Nagesh, AudioEngine-eer Béla Balázs, Audio Artisan Torrey Holbrook Walker, Audio/MIDI Black Ops

Using Grouped Notifications

Monetize and Promote Your App with iad

Writing Energy Efficient Apps

Using and Extending the Xcode Source Editor

What s New in Device Configuration, Deployment, and Management

Modern User Interaction on ios

Introducing the Photos Frameworks

Core ML in Depth. System Frameworks #WWDC17. Krishna Sridhar, Core ML Zach Nation, Core ML

Advances in TVMLKit. App Frameworks #WWDC17. Trevor Cortez, Localization Engineer Parry Panesar, tvos Engineer Jeremy Foo, tvos Engineer

Localizing with Xcode 9

Vision Framework. Building on Core ML. Media #WWDC17. Brett Keating, Apple Manager Frank Doepke, He who wires things together

Touch Bar Fundamentals

Creating Audio Apps for watchos

Mastering UIKit on tvos

Securing APIs and Microservices with OAuth and OpenID Connect

Insider Tips for using Music Station & Qmusic

Swift API Design Guidelines

Your Apps and the Future of macos Security

What s New in Notifications

Your Apps and Evolving Network Security Standards

What's New in Core Spotlight

Securing ArcGIS Server Services An Introduction

Advances in AVFoundation Playback

Getting the Most Out of HealthKit

CloudKit Tips And Tricks

Extending Your Apps with SiriKit

CS193P - Lecture 16. iphone Application Development. Audio APIs Video Playback Displaying Web Content Settings

CS144: Sessions. Cookie : CS144: Web Applications

Convert Technologies ION EZ Vinyl 2 App (ios version)

Media AI. Adaptive. Intelligent. Architectural Design Document

Managing Documents In Your ios Apps

CarPlay Audio and Navigation Apps

CS193p Spring 2010 Wednesday, May 26, 2010

ArcGIS Server and Portal for ArcGIS An Introduction to Security

Localization Best Practices on tvos

How to configure your Triton Player

What s New in Swift Playgrounds

imessage Apps and Stickers, Part 2

Music, Radio & Podcasts

ESOTERIC Sound Stream. User s Manual

What s New in ARKit 2

Introducing the Contacts Framework

AVContentKeySession Best Practices

Multitasking Support on the ios Platform

Can the app be installed on the device? Does the app behave as designed/desired if there is an incoming SMS?

Building for Voice with Siri Shortcuts

What s New in imessage Apps

FREEGAL MUSIC. Freegal Music offers access to nearly 3 million songs, including Sony Music s catalog of legendary artists.

USER MANUAL NAIM DESKTOP CLIENT INTERFACE E N G L I S H

Introducing CloudKit. A how-to guide for icloud for your Apps. Frameworks #WWDC14. Session 208 Olivier Bonnet CloudKit Client Software

Building Apps with Dynamic Type

Integration Note. Ovation Summit OS Solo & Duet, some OMS(x) Fusion Research, Inc.

HLS Authoring Update. Media #WWDC17. Eryk Vershen, AVFoundation Engineer

Implementing UI Designs in Interface Builder

MEDIAMPLIFY : A Cloud to Cable TV Platform for Music, TV, and Video Dr. Edwin A. Hernandez Chief Technology Officer EGLA COMMUNICATIONS

Fix the Missing Tags in your MP3 Files

ArcGIS Enterprise Security: An Introduction. Gregory Ponto & Jeff Smith

Queens Library API Requirements Document For e-content Partners

We make Apple Better. Quick Start Guide FEB ONE

What s New in MapKit. App Frameworks #WWDC17. Fredrik Olsson

What s New in SiriKit

Freegal emusic PC user guide

Finding Bugs Using Xcode Runtime Tools

ArcGIS Enterprise Security: An Introduction. Randall Williams Esri PSIRT

Connect. explained. Vladimir Dzhuvinov. :

Working with Metal Overview

New Ways to Work with Workouts

Building Visually Rich User Experiences

General. What is Freegal?

Advanced Notifications

Designing Great Apple Watch Experiences

Validating HTTP Live Streams

Introducing the Modern WebKit API

Audio Servers S1, H1, H3, H5CD and Others

COPYRIGHTED MATERIAL. chapter 1. How Do I Configure My iphone? 2

Building Faster in Xcode

Getting Published in Apple News

What s New in tvos 12

Getting Started with CareKit

Display Audio Operation

Accessibility on ios. Developing for everyone. Frameworks #WWDC14. Session 210 Clare Kasemset ios Accessibility

Transcription:

Session Media #WWDC17 Introducing MusicKit 502 Tim Parthemore, MusicKit Services Joel Lopes Da Silva, ios Music 2017 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

Apple Music Content Artists

Apple Music Content Artists Albums

Apple Music Content Artists Albums Playlists

Apple Music Content Artists Albums Playlists Curators

Apple Music Discovery Search

Apple Music Discovery Search Charts

Apple Music Discovery Search Charts Recommendations

MusicKit

MusicKit ios Frameworks

MusicKit ios Frameworks HTTPS Apple Music API Catalog Services Personalized Services

Apple Music API Tim Parthemore, MusicKit Services

Request format Resource representations and relationships Limits and pagination Demo Personalized services API Access

Apple Music API Catalog https://api.music.apple.com

Apple Music API Catalog https://api.music.apple.com/{version} Versioned

Apple Music API Catalog https://api.music.apple.com/{version}/catalog Versioned

Apple Music API Catalog https://api.music.apple.com/{version}/catalog/{storefront} Versioned Storefront scopes the catalog

Apple Music API Catalog https://api.music.apple.com/{version}/catalog /{storefront}/{api} Versioned Storefront scopes the catalog

Apple Music API Catalog https://api.music.apple.com/{version}/catalog /{storefront}/{api}?[params] Versioned Storefront scopes the catalog

Apple Music API Catalog https://api.music.apple.com/{version}/catalog /{storefront}/{api}?[params] Versioned Storefront scopes the catalog Localized

Apple Music API Catalog https://api.music.apple.com/{version}/catalog /{storefront}/{api}?[params] Versioned Storefront scopes the catalog Localized Limits and pagination

Apple Music API Catalog https://api.music.apple.com/{version}/catalog /{storefront}/{api}?[params] Versioned Storefront scopes the catalog Localized Limits and pagination Requires a developer token

Apple Music API Resource representations id type {"data": [{ "id": "1200868601", "type": "albums", "href": "/v1/catalog/us/albums/1200868601"}]} href

Apple Music API Resource representations id type href attributes {"data": [{ "id": "1200868601", "type": "albums", "href": "/v1/catalog/us/albums/1200868601"}]} "/v1/catalog/us/albums/1200868601", "attributes": { "artwork": { }, "artistname": "Khalid", "discnumber": 1, "genrenames": "playparams": ["R&B/Soul", { }, "Music"], "releasedate": "2017-03-03", "tracknumber": 15}}]}

Apple Music API Resource representations id type href attributes relationships {"data": [{ "id": "1200868601", "type": "albums", "href": "/v1/catalog/us/albums/1200868601"}]} "/v1/catalog/us/albums/1200868601", "attributes": { }, "relationships": "artwork": { }, { "artistname": "tracks": "Khalid", { "discnumber": "data": 1, [{ },,{ }], "href": /v1/ /albums/1200868601/tracks "/v1/ /albums/1200868601/tracks" }, "genrenames": "playparams": "artists": ["R&B/Soul", { }, { "Music"], "releasedate": "data": "2017-03-03", [{ }], "tracknumber": "href": 15}}]} /v1/ /albums/1200868601/artists }}}]} "/v1/ /albums/1200868601/artists"}}}]}

Apple Music API Resource relationships

Apple Music API Resource relationships Album Resource id type href attributes

Apple Music API Resource relationships Album Resource tracks id type href attributes

Apple Music API Resource relationships Album Resource tracks id type artists href attributes

Apple Music API Resource relationships Album Resource tracks id type artists href attributes genres

Apple Music API Resource relationships Album Resource id Attributes included tracks Song id type href attributes type href artists attributes genres

Apple Music API Resource relationships Album Resource id type href Attributes included tracks Identifiers only artists Song id type href attributes Artist id type href attributes genres

Apple Music API Resource relationships Album Resource id type href attributes Attributes included tracks Identifiers only artists Omitted genres Song id type href attributes Artist id type href

https://api.music.apple.com/v1/catalog/us/albums/1200868601 "relationships": { "tracks": {"data": [{"id": "548392190", "type": "songs", "href": "/v1/catalog/us/songs/548392190", "attributes": { }}, {"id": "548392191", "type": "songs", "href": "/v1/catalog/us/songs/548392191" "attributes": { }}], "href": "/v1/catalog/us/albums/1200868601/tracks"}, "artists": {"data": [{"id": "82842423", "type": "artists", "href": "/v1/catalog/us/artists/82842423"}], "href": "/v1/catalog/us/albums/1200868601/artists"}}

https://api.music.apple.com/v1/catalog/us/albums/1200868601 "relationships": { "tracks": {"data": [{"id": "548392190", "type": "songs", "href": "/v1/catalog/us/songs/548392190", "attributes": { }}, {"id": "548392191", "type": "songs", "href": "/v1/catalog/us/songs/548392191" "attributes": { }}], "href": "/v1/catalog/us/albums/1200868601/tracks"}, "artists": {"data": [{"id": "82842423", "type": "artists", "href": "/v1/catalog/us/artists/82842423"}], "href": "/v1/catalog/us/albums/1200868601/artists"}}

https://api.music.apple.com/v1/catalog/us/albums/1200868601 "relationships": { "tracks": {"data": [{"id": "548392190", "type": "songs", "href": "/v1/catalog/us/songs/548392190", "attributes": { }}, {"id": "548392191", "type": "songs", "href": "/v1/catalog/us/songs/548392191" "attributes": { }}], "href": "/v1/catalog/us/albums/1200868601/tracks"}, "artists": {"data": [{"id": "82842423", "type": "artists", "href": "/v1/catalog/us/artists/82842423"}], "href": "/v1/catalog/us/albums/1200868601/artists"}}

https://api.music.apple.com/v1/catalog/us/albums/1200868601?include=artists "relationships": { "tracks": { }, "artists": {"data": [{ "id": "1200868601", "type": "artists", "href": "/v1/catalog/us/artists/82842423", "attributes": { "genrenames": ["R&B/Soul","Hip-Hop/Rap", "Rap"] "isgroup": false, "name": "Khalid", } }], "href": "/v1/catalog/us/albums/1200868601/artists"}}

https://api.music.apple.com/v1/catalog/us/albums/1200868601?include=artists "relationships": { "tracks": { }, "artists": {"data": [{ "id": "1200868601", "type": "artists", "href": "/v1/catalog/us/artists/82842423", "attributes": { "genrenames": ["R&B/Soul","Hip-Hop/Rap", "Rap"] "isgroup": false, "name": "Khalid", } }], "href": "/v1/catalog/us/albums/1200868601/artists"}}

https://api.music.apple.com/v1/catalog/us/albums/1200868601?include=artists,genres "relationships": { "tracks": { }, "artists": { } "genres": {"data": [{"id": "14", }} "type": "genres", "href": "/v1/catalog/us/genres/14", "attributes": { "name": "Pop"}}, {"id": "34", "type": "genres", "href": "/v1/catalog/us/genres/34", "attributes": { "name": "Music"}], "href": "/v1/catalog/us/albums/1200868601/genres"

https://api.music.apple.com/v1/catalog/us/albums/1200868601?include=artists,genres "relationships": { "tracks": { }, "artists": { } "genres": {"data": [{"id": "14", }} "type": "genres", "href": "/v1/catalog/us/genres/14", "attributes": { "name": "Pop"}}, {"id": "34", "type": "genres", "href": "/v1/catalog/us/genres/34", "attributes": { "name": "Music"}], "href": "/v1/catalog/us/albums/1200868601/genres"

Apple Music API Limits and pagination https://api.music.apple.com/v1/catalog/us/albums/1200868601/tracks

Apple Music API Limits and pagination https://api.music.apple.com/v1/catalog/us/albums/1200868601/tracks Song 9 Song 8 Song 7 id Song 6 id Song 5 id type Song 4 id type Song 3 id type Song 2 id href type Song 1 id href type id href type attributes id href type attributes href type attributes href type attributes href attributes href attributes href attributes attributes attributes

Apple Music API Limits and pagination https://api.music.apple.com/v1/catalog/us/albums/1200868601/tracks

Apple Music API Limits and pagination https://api.music.apple.com/v1/catalog/us/albums/1200868601/tracks?limit=2

Apple Music API Limits and pagination https://api.music.apple.com/v1/catalog/us/albums/1200868601/tracks?limit=2 Song 2 Song 1 id id type type href href attributes attributes

Apple Music API Limits and pagination https://api.music.apple.com/v1/catalog/us/albums/1200868601/tracks?limit=2 Song 2 Song 1 id id type type href href attributes attributes next

Apple Music API Limits and pagination https://api.music.apple.com/v1/catalog/us/albums/1200868601/tracks?limit=2 Song 2 Song 1 id id type type href href attributes attributes next /v1/catalog/us/albums/1200868601/tracks?offset=2

Apple Music API Limits and pagination https://api.music.apple.com/v1/catalog/us/albums/1200868601/tracks?offset=2

Apple Music API Limits and pagination https://api.music.apple.com/v1/catalog/us/albums/1200868601/tracks?offset=2 Song 9 Song 8 Song 7 id Song 6 id Song 5 id type Song 4 id type Song 3 id type id href type id href type href type attributes href type attributes href attributes href attributes href attributes attributes attributes

Apple Music API Limits and pagination https://api.music.apple.com/v1/catalog/us/albums/1200868601/tracks?offset=2

Apple Music API Limits and pagination https://api.music.apple.com/v1/catalog/us/albums/1200868601/tracks?offset=2&limit=2

Apple Music API Limits and pagination https://api.music.apple.com/v1/catalog/us/albums/1200868601/tracks?offset=2&limit=2 Song 4 Song 3 id id type type href href attributes attributes

Apple Music API Limits and pagination https://api.music.apple.com/v1/catalog/us/albums/1200868601/tracks?offset=2&limit=2 Song 4 Song 3 id id type type href href attributes attributes next

Apple Music API Limits and pagination https://api.music.apple.com/v1/catalog/us/albums/1200868601/tracks?offset=2&limit=2 Song 4 Song 3 id id type type href href attributes attributes next /v1/catalog/us/albums/1200868601/tracks?offset=4

https://api.music.apple.com/v1/catalog/us/albums/1200868601/tracks?limit=2 {"data": [{ "attributes": { }, "href": "/v1/catalog/us/songs/1200868616", "id": "1200868616", "relationships": { } "type": "songs" }, { "attributes": { }, "href": "/v1/catalog/us/songs/1200868874", "id": "1200868874", "relationships": { }, "type": "songs" }], "next": "/v1/catalog/us/albums/1200868601/tracks?offset=2"}

Apple Music API Search https://api.music.apple.com/v1/catalog/us/search?term=khalid albums artists songs playlists Album Artists Song Playlist id id id id type type type type href href href href attributes attributes attributes attributes

Apple Music API Search https://api.music.apple.com/v1/catalog/us/search?term=khalid&types=albums albums artists songs playlists Album Artists Song Playlist id id id id type type type type href href href href attributes attributes attributes attributes

Apple Music API Search https://api.music.apple.com/v1/catalog/us/search?term=khalid&types=albums albums Album id type href attributes

Demo Apple Music Catalog Search Joel Lopes Da Silva, ios Music

Apple Music API Personalized https://api.music.apple.com/v1/me/recent/played User must have an Apple Music Subscription Required tokens Developer token Music user token

API Access Requirements

API Access Requirements Apple Developer Program membership

API Access Requirements Apple Developer Program membership MusicKit private key

API Access Requirements Apple Developer Program membership MusicKit private key Developer token JSON Web Token (RFC 7519) Required in the Authorization header for every Apple Music API request

API Access Requirements Apple Developer Program membership MusicKit private key Developer token JSON Web Token (RFC 7519) Required in the Authorization header for every Apple Music API request Security Protect your MusicKit private key Recommend dynamically generating developer tokens

API Access More about the developer token

API Access More about the developer token Required Headers - Encryption Algorithm (alg), Key Identifier (kid) { } "alg": "ES256", "kid": "ABC123DEFG"

API Access More about the developer token Required Headers - Encryption Algorithm (alg), Key Identifier (kid) Required Claims - Issuer/Team ID (iss), Issued at (iat), Expiration (exp) { } { } "alg": "ES256", "kid": "ABC123DEFG" "iss": "DEF123GHIJ", "iat": 1437179036, "exp": 1493298100

Using MusicKit on ios Joel Lopes Da Silva, ios Music

Get access to Apple Music API Allow users to subscribe Play subscription and library content

Get access to Apple Music API Allow users to subscribe Play subscription and library content

Privacy and User Consent Most users are already signed in No need to authenticate to use MusicKit Requires user consent User consent is per ios device and per app

Requesting User Consent Needed to access device library or get the music user token Reading authorization status will not prompt Requesting will prompt unless already authorized

Requesting User Consent Needed to access device library or get the music user token Reading authorization status will not prompt Requesting will prompt unless already authorized SKCloudServiceController.requestAuthorization { (status: SKCloudServiceAuthorizationStatus) in switch status { case.authorized: case.denied,.restricted: case.notdetermined: } }

Fetching Subscription Status

Fetching Subscription Status Actual status may be complex

Fetching Subscription Status Actual status may be complex We expose three capabilities: Music catalog playback Add to icloud Music Library Can become subscriber

Fetching Subscription Status Actual status may be complex We expose three capabilities: Music catalog playback Add to icloud Music Library Can become subscriber Check each capability before corresponding app action

Fetching Subscription Status Requires user consent or else you get an error let controller = SKCloudServiceController() controller.requestcapabilities { (capabilities: SKCloudServiceCapability, error: Error?) in let canplay = capabilities.contains(.musiccatalogplayback) let canadd = capabilities.contains(.addtocloudmusiclibrary) let cansubscribe = capabilities.contains(.musiccatalogsubscriptioneligible) }

Fetching Storefront Country Code Content identifiers vary across storefronts let controller = SKCloudServiceController() controller.requeststorefrontcountrycode { (countrycode: String?, error: Error?) in if let storefrontcountrycode = countrycode { } }

Fetching Storefront Country Code Content identifiers vary across storefronts let controller = SKCloudServiceController() controller.requeststorefrontcountrycode { (countrycode: String?, error: Error?) in if let storefrontcountrycode = countrycode { var topsongsurlcomponents = URLComponents() topsongsurlcomponents.scheme = "https" topsongsurlcomponents.host = "api.music.apple.com" topsongsurlcomponents.path = "/v1/catalog/\(storefrontcountrycode)/charts" topsongsurlcomponents.queryitems = [URLQueryItem(name: "types", value: "songs")] } }

Fetching Storefront Country Code Content identifiers vary across storefronts let controller = SKCloudServiceController() controller.requeststorefrontcountrycode { (countrycode: String?, error: Error?) in if let storefrontcountrycode = countrycode { var topsongsurlcomponents = URLComponents() topsongsurlcomponents.scheme = "https" topsongsurlcomponents.host = "api.music.apple.com" topsongsurlcomponents.path = "/v1/catalog/\(storefrontcountrycode)/charts" topsongsurlcomponents.queryitems = [URLQueryItem(name: "types", value: "songs")] } }

Fetching Music User Token From your developer token You should cache the token, but don t transfer it across devices Refetch if you get a Forbidden status code (403) from Apple Music API

Fetching Music User Token let developertoken = "ey " let controller = SKCloudServiceController() controller.requestusertoken(fordevelopertoken: developertoken) { (usertoken: String?, error: Error?) in if let musicusertoken = usertoken { } }

Fetching Music User Token let developertoken = "ey " let controller = SKCloudServiceController() controller.requestusertoken(fordevelopertoken: developertoken) { (usertoken: String?, error: Error?) in if let musicusertoken = usertoken { var request = URLRequest(url: recentlyplayedurl) request.setvalue("bearer \(developertoken)", forhttpheaderfield: "Authorization") request.setvalue(musicusertoken, forhttpheaderfield: "Music-User-Token") } }

Fetching Music User Token let developertoken = "ey " let controller = SKCloudServiceController() controller.requestusertoken(fordevelopertoken: developertoken) { (usertoken: String?, error: Error?) in if let musicusertoken = usertoken { var request = URLRequest(url: recentlyplayedurl) request.setvalue("bearer \(developertoken)", forhttpheaderfield: "Authorization") request.setvalue(musicusertoken, forhttpheaderfield: "Music-User-Token") } }

Get access to Apple Music API Allow users to subscribe Play subscription and library content

When to Show the Subscription View? Only if.musiccatalogplayback capability is disabled and.musiccatalogsubscriptioneligible is enabled

Configure the Subscription View Choose the main message Optional:.messageIdentifier Default:.join

Configure the Subscription View Choose the main message Optional:.messageIdentifier Default:.join Other values:

Configure the Subscription View Choose the main message Optional:.messageIdentifier Default:.join Other values:.connect

Configure the Subscription View Choose the main message Optional:.messageIdentifier Default:.join Other values:.connect.addmusic

Configure the Subscription View Choose the main message Optional:.messageIdentifier Default:.join Other values:.connect.addmusic.playmusic

Configure the Subscription View Contextual offer Optional:.iTunesItemIdentifier Type: String Supported content types: songs albums playlists radio stations

Configure the Subscription View Other options Key Value.action.subscribe Required.affiliateToken String Optional.campaignToken String Optional

// Showing Subscription View let setupviewcontroller = SKCloudServiceSetupViewController() setupviewcontroller.delegate = self let setupoptions: [SKCloudServiceSetupOptionsKey: Any] = [.action: SKCloudServiceSetupAction.subscribe,.messageIdentifier: SKCloudServiceSetupMessageIdentifier.playMusic ] setupviewcontroller.load(options: setupoptions) { (didsucceedloading: Bool, error: Error?) in if didsucceedloading { self.present(setupviewcontroller, animated: true, completion: nil) } })

// Showing Subscription View let setupviewcontroller = SKCloudServiceSetupViewController() setupviewcontroller.delegate = self let setupoptions: [SKCloudServiceSetupOptionsKey: Any] = [.action: SKCloudServiceSetupAction.subscribe,.messageIdentifier: SKCloudServiceSetupMessageIdentifier.playMusic ] setupviewcontroller.load(options: setupoptions) { (didsucceedloading: Bool, error: Error?) in if didsucceedloading { self.present(setupviewcontroller, animated: true, completion: nil) } })

// Showing Subscription View let setupviewcontroller = SKCloudServiceSetupViewController() setupviewcontroller.delegate = self let setupoptions: [SKCloudServiceSetupOptionsKey: Any] = [.action: SKCloudServiceSetupAction.subscribe,.messageIdentifier: SKCloudServiceSetupMessageIdentifier.playMusic ] setupviewcontroller.load(options: setupoptions) { (didsucceedloading: Bool, error: Error?) in if didsucceedloading { self.present(setupviewcontroller, animated: true, completion: nil) } })

// Showing Subscription View let setupviewcontroller = SKCloudServiceSetupViewController() setupviewcontroller.delegate = self let setupoptions: [SKCloudServiceSetupOptionsKey: Any] = [.action: SKCloudServiceSetupAction.subscribe,.messageIdentifier: SKCloudServiceSetupMessageIdentifier.playMusic ] setupviewcontroller.load(options: setupoptions) { (didsucceedloading: Bool, error: Error?) in if didsucceedloading { self.present(setupviewcontroller, animated: true, completion: nil) } })

// Showing Subscription View let setupviewcontroller = SKCloudServiceSetupViewController() setupviewcontroller.delegate = self let setupoptions: [SKCloudServiceSetupOptionsKey: Any] = [.action: SKCloudServiceSetupAction.subscribe,.messageIdentifier: SKCloudServiceSetupMessageIdentifier.playMusic ] setupviewcontroller.load(options: setupoptions) { (didsucceedloading: Bool, error: Error?) in if didsucceedloading { self.present(setupviewcontroller, animated: true, completion: nil) } })

Get access to Apple Music API Allow users to subscribe Play subscription and library content

Two Players MPMusicPlayerController systemmusicplayer applicationqueueplayer

Two Players MPMusicPlayerController systemmusicplayer applicationqueueplayer Example

Two Players MPMusicPlayerController systemmusicplayer applicationqueueplayer Example Social networking app

Two Players MPMusicPlayerController systemmusicplayer applicationqueueplayer Example Social networking app Fitness app

Two Players MPMusicPlayerController systemmusicplayer applicationqueueplayer Example Social networking app Fitness app Now Playing info reporting Remote commands handling

Two Players MPMusicPlayerController systemmusicplayer applicationqueueplayer Example Social networking app Fitness app Now Playing info reporting Remote commands handling Now Playing app Music app Your app

Two Players MPMusicPlayerController systemmusicplayer applicationqueueplayer Example Social networking app Fitness app Now Playing info reporting Remote commands handling Now Playing app Music app Your app Playback queue ownership Remote-controlling the Music app Your app owns the queue

Two Players MPMusicPlayerController systemmusicplayer applicationqueueplayer Example Social networking app Fitness app Now Playing info reporting Remote commands handling Now Playing app Music app Your app Playback queue ownership Remote-controlling the Music app Your app owns the queue Set queue / Play next / Play later

Two Players MPMusicPlayerController systemmusicplayer applicationqueueplayer Example Social networking app Fitness app Now Playing info reporting Remote commands handling Now Playing app Music app Your app Playback queue ownership Remote-controlling the Music app Your app owns the queue Set queue / Play next / Play later Insert items in the middle / Remove items

Queue Descriptors Data Use Case

Queue Descriptors Data Use Case Media Item MPMediaItem MPMediaItemCollection Device library queries (MPMediaQuery) Media picker

Queue Descriptors Data Use Case Media Item MPMediaItem MPMediaItemCollection Device library queries (MPMediaQuery) Media picker Store Queue Store IDs (String) Catalog content (e.g. catalog search)

Queue Descriptors Data Use Case Media Item MPMediaItem MPMediaItemCollection Device library queries (MPMediaQuery) Media picker Store Queue Store IDs (String) Catalog content (e.g. catalog search) Play Parameters Dictionaries Personalized content (e.g. recently played)

let player = MPMusicPlayerController.systemMusicPlayer player.repeatmode =.all let album: MPMediaItemCollection =... let albumqueuedescriptor = MPMusicPlayerMediaItemQueueDescriptor(itemCollection: album) albumqueuedescriptor.startitem = album.items[3] player.setqueue(with: albumqueuedescriptor) let catalogsongstoreid: String =... let catalogqueuedescriptor = MPMusicPlayerStoreQueueDescriptor(storeIDs: [catalogsongstoreid]) player.prepend(catalogqueuedescriptor) let recentlyplayedsongplayparameters: [String: Any] =... let recentlyplayedsongqueuedescriptor = MPMusicPlayerPlayParametersQueueDescriptor( playparametersqueue: [recentlyplayedsongplayparameters] ) player.append(recentlyplayedsongqueuedescriptor)

let player = MPMusicPlayerController.systemMusicPlayer player.repeatmode =.all let album: MPMediaItemCollection =... let albumqueuedescriptor = MPMusicPlayerMediaItemQueueDescriptor(itemCollection: album) albumqueuedescriptor.startitem = album.items[3] player.setqueue(with: albumqueuedescriptor) let catalogsongstoreid: String =... let catalogqueuedescriptor = MPMusicPlayerStoreQueueDescriptor(storeIDs: [catalogsongstoreid]) player.prepend(catalogqueuedescriptor) let recentlyplayedsongplayparameters: [String: Any] =... let recentlyplayedsongqueuedescriptor = MPMusicPlayerPlayParametersQueueDescriptor( playparametersqueue: [recentlyplayedsongplayparameters] ) player.append(recentlyplayedsongqueuedescriptor)

let player = MPMusicPlayerController.systemMusicPlayer player.repeatmode =.all let album: MPMediaItemCollection =... let albumqueuedescriptor = MPMusicPlayerMediaItemQueueDescriptor(itemCollection: album) albumqueuedescriptor.startitem = album.items[3] player.setqueue(with: albumqueuedescriptor) let catalogsongstoreid: String =... let catalogqueuedescriptor = MPMusicPlayerStoreQueueDescriptor(storeIDs: [catalogsongstoreid]) player.prepend(catalogqueuedescriptor) let recentlyplayedsongplayparameters: [String: Any] =... let recentlyplayedsongqueuedescriptor = MPMusicPlayerPlayParametersQueueDescriptor( playparametersqueue: [recentlyplayedsongplayparameters] ) player.append(recentlyplayedsongqueuedescriptor)

let player = MPMusicPlayerController.systemMusicPlayer player.repeatmode =.all let album: MPMediaItemCollection =... let albumqueuedescriptor = MPMusicPlayerMediaItemQueueDescriptor(itemCollection: album) albumqueuedescriptor.startitem = album.items[3] player.setqueue(with: albumqueuedescriptor) let catalogsongstoreid: String =... let catalogqueuedescriptor = MPMusicPlayerStoreQueueDescriptor(storeIDs: [catalogsongstoreid]) player.prepend(catalogqueuedescriptor) let recentlyplayedsongplayparameters: [String: Any] =... let recentlyplayedsongqueuedescriptor = MPMusicPlayerPlayParametersQueueDescriptor( playparametersqueue: [recentlyplayedsongplayparameters] ) player.append(recentlyplayedsongqueuedescriptor)

let player = MPMusicPlayerController.systemMusicPlayer player.repeatmode =.all let album: MPMediaItemCollection =... let albumqueuedescriptor = MPMusicPlayerMediaItemQueueDescriptor(itemCollection: album) albumqueuedescriptor.startitem = album.items[3] player.setqueue(with: albumqueuedescriptor) let catalogsongstoreid: String =... let catalogqueuedescriptor = MPMusicPlayerStoreQueueDescriptor(storeIDs: [catalogsongstoreid]) player.prepend(catalogqueuedescriptor) let recentlyplayedsongplayparameters: [String: Any] =... let recentlyplayedsongqueuedescriptor = MPMusicPlayerPlayParametersQueueDescriptor( playparametersqueue: [recentlyplayedsongplayparameters] ) player.append(recentlyplayedsongqueuedescriptor)

// Advanced Queue Editing using applicationqueueplayer let player = MPMusicPlayerController.applicationQueuePlayer player.perform( queuetransaction: { (mutablequeue: MPMusicPlayerControllerMutableQueue) in // Remove 3rd item mutablequeue.remove(mutablequeue.items[2]) ) // Add song with storeid after 5th item let songstoreid: String =... let songqueuedescriptor = MPMusicPlayerStoreQueueDescriptor(storeIDs: [songstoreid]) mutablequeue.insert(songqueuedescriptor, after: mutablequeue.items[4]) }, completionhandler: { (queue: MPMusicPlayerControllerQueue, error: Error?) in }

// Advanced Queue Editing using applicationqueueplayer let player = MPMusicPlayerController.applicationQueuePlayer player.perform( queuetransaction: { (mutablequeue: MPMusicPlayerControllerMutableQueue) in // Remove 3rd item mutablequeue.remove(mutablequeue.items[2]) ) // Add song with storeid after 5th item let songstoreid: String =... let songqueuedescriptor = MPMusicPlayerStoreQueueDescriptor(storeIDs: [songstoreid]) mutablequeue.insert(songqueuedescriptor, after: mutablequeue.items[4]) }, completionhandler: { (queue: MPMusicPlayerControllerQueue, error: Error?) in }

// Advanced Queue Editing using applicationqueueplayer let player = MPMusicPlayerController.applicationQueuePlayer player.perform( queuetransaction: { (mutablequeue: MPMusicPlayerControllerMutableQueue) in // Remove 3rd item mutablequeue.remove(mutablequeue.items[2]) ) // Add song with storeid after 5th item let songstoreid: String =... let songqueuedescriptor = MPMusicPlayerStoreQueueDescriptor(storeIDs: [songstoreid]) mutablequeue.insert(songqueuedescriptor, after: mutablequeue.items[4]) }, completionhandler: { (queue: MPMusicPlayerControllerQueue, error: Error?) in }

// Advanced Queue Editing using applicationqueueplayer let player = MPMusicPlayerController.applicationQueuePlayer player.perform( queuetransaction: { (mutablequeue: MPMusicPlayerControllerMutableQueue) in // Remove 3rd item mutablequeue.remove(mutablequeue.items[2]) ) // Add song with storeid after 5th item let songstoreid: String =... let songqueuedescriptor = MPMusicPlayerStoreQueueDescriptor(storeIDs: [songstoreid]) mutablequeue.insert(songqueuedescriptor, after: mutablequeue.items[4]) }, completionhandler: { (queue: MPMusicPlayerControllerQueue, error: Error?) in }

// Advanced Queue Editing using applicationqueueplayer let player = MPMusicPlayerController.applicationQueuePlayer player.perform( queuetransaction: { (mutablequeue: MPMusicPlayerControllerMutableQueue) in // Remove 3rd item mutablequeue.remove(mutablequeue.items[2]) ) // Add song with storeid after 5th item let songstoreid: String =... let songqueuedescriptor = MPMusicPlayerStoreQueueDescriptor(storeIDs: [songstoreid]) mutablequeue.insert(songqueuedescriptor, after: mutablequeue.items[4]) }, completionhandler: { (queue: MPMusicPlayerControllerQueue, error: Error?) in }

// Advanced Queue Editing using applicationqueueplayer let player = MPMusicPlayerController.applicationQueuePlayer player.perform( queuetransaction: { (mutablequeue: MPMusicPlayerControllerMutableQueue) in // Remove 3rd item mutablequeue.remove(mutablequeue.items[2]) ) // Add song with storeid after 5th item let songstoreid: String =... let songqueuedescriptor = MPMusicPlayerStoreQueueDescriptor(storeIDs: [songstoreid]) mutablequeue.insert(songqueuedescriptor, after: mutablequeue.items[4]) }, completionhandler: { (queue: MPMusicPlayerControllerQueue, error: Error?) in }

Timeframe

Timeframe

Timeframe ios 10.3 Music user tokens (Fall) 1 Storefront country code 2 Catalog playback (with store IDs) *1 API in SKCloudServiceController exists under a different name. *2 As an approximation, you can use Locale.current.regionCode.

Timeframe ios 10.3 ios 11 Music user tokens (Fall) 1 Storefront country code 2 Catalog playback (with store IDs) Music user tokens Storefront country code Catalog playback (with store IDs) Catalog playback (with parameters) 3 *1 API in SKCloudServiceController exists under a different name. *2 As an approximation, you can use Locale.current.regionCode. *3 Available in an upcoming ios 11 Beta.

Summary Leverage Apple Music s content to keep your users engaged Get music user token from ios Use it to call Apple Music API Use Media Player to control playback

More Information https://developer.apple.com/wwdc17/502

Related Sessions What's New in Audio Grand Ballroom B Tuesday 1:50PM What's New in Foundation Hall 2 Wednesday 11:00AM Introducing AirPlay 2 Executive Ballroom Thursday 4:10PM

Labs MusicKit Lab Technology Lab G Tue 4:10PM-6:00PM Audio Lab Technology Lab F Tue 4:10PM-6:00PM Foundation Lab Technology Lab C Wed 1:00PM-3:10PM MusicKit Lab Technology Lab F Wed 3:10PM-6:00PM Audio Lab Technology Lab G Thur 1:00PM-3:00PM