Upgrade to Pro — share decks privately, control downloads, hide ads and more …

プロトコルを使って複数サービスを跨いだmusic playerを実装する

Hiroki Kumamoto
September 02, 2018
520

プロトコルを使って複数サービスを跨いだmusic playerを実装する

Hiroki Kumamoto

September 02, 2018
Tweet

Transcript

  1. ࣗݾ঺հ • Hiroki Kumamoto • a.k.a kumabook (twitter, github) •

    Software engineer at Spincoaster, Inc. • swift, JavaScript, ruby, rust ...
  2. TYPICA • ԻָϙʔλϧΞϓϦ • @TYPICA_JP • Web: typica.mu • iOSΞϓϦ

    • ʰϦΞϧͳԻָγʔϯͷՄࢹԽʱΛ໨ࢦͨ͠ԻָαʔϏε • Web্ͷԻָ৘ใΛΫϩʔϧͯ͠Ϩίϝϯυ • Իָʹؔ͢Δهࣄ΍ԻָαʔϏεͷۂɺΞϧόϜɺϓϨΠϦετ • TYPICA Top 100 (https://typica.mu/ja/chart/top100) • ಠࣗͷϥϯΩϯάγεςϜ
  3. iOSͰԻָΛ࠶ੜ͢Δ • AVFoundation.AVPlayer • MediaPlayer.MPMusicPlayerController • WebView • Spotify iOS

    SDK • ௿ϨΠϠͷAPIΛ࢖͏ (ࠓճ͸είʔϓ֎) • CoreAudio, AudioUnit, OpenAL …
  4. AppleMusicΞΧ΢ϯτ઀ଓͷखॱ 1. Info.plist ʹNSAppleMusicUsageDescriptionΛ௥Ճ 2. SKCloudServiceController.authorizationStatusͰݱࡏͷঢ়ଶΛ֬ ೝ 3. SKCloudServiceController.requestAuthorizationͰ઀ଓཁٻ 4.

    SKCloudServiceController#requestCapabilities
 Ͱ࠶ੜՄೳ͔ΛνΣοΫ 5. SKCloudServiceController#requestStorefrontCountryCodeͰ StorefrontΛऔಘ
  5. Apple Music API • AppleMusicͷ৘ใΛऔಘ͢ΔͨΊͷWebAPI • αʔόͰ΋ར༻Մೳ • StorefrontΛࢦఆ •

    ݁Ռͷݴޠ͕มΘΔ • ̎छྨͷtoken • developer token • user token
  6. developer tokenͷੜ੒ • https://developer.apple.com/ -> Certificates, Identifiers & Profiles •

    Identities -> Music IDͷ࡞੒ • Keys -> MusicKit private key ͷ࡞੒ • JWTͷੜ੒ • elauimagineering/apple-music-token-generator • key idɾteam idɾprivate key • ΫϥΠΞϯτʹ͸private key͸ຒΊࠐ·ͳ͍ํ͕ྑ͍
  7. Spotify iOS SDK • Spotify accountͰOAuth ϩάΠϯ • SPTAudioStreamingControllerʹaccess tokenΛ

    ηοτ • ࠶ੜ͢ΔTrackͷuriΛWeb APIͳͲͰऔಘ • SPTAudioStreamingController#playSpotifyURI
  8. όοΫάϥϯυ࠶ੜ • Capabilities -> Background Modes -> Audio ,... ʹνΣοΫ

    • AVAudioSession#setCategory() • AVAudioSessionCategoryPlayback
  9. αʔϏεͱϓϨʔϠʔ • SoundCloud • YouTube • Spotify • AppleMusic ←

    AVPlayer ← WebView ← spotify/ios-sdk ← MediaPlayer
  10. init load loadTo Play play pause play(_: Track) prepare(_: Track)

    [complete loading] [complete loading] pause() play() [end to play] Playerͷঢ়ଶભҠ: PlayerState
  11. Player • var state: PlayerState { get } • func

    clearPlayer() : Πϕϯτ؂ࢹͷղ์ɺλΠ ϚʔͷΫϦΞ • func preparePlayer(): Πϕϯτ؂ࢹɺλΠϚʔε λʔτɺঢ়ଶΛॳظঢ়ଶ΁
  12. init load loadTo Play play pause play(_: Track) prepare(_: Track)

    [complete loading] [complete loading] pause() play() [end (queue is empty)] QueuePlayerͷঢ়ଶભҠ next() 
 previous()
 [end]