Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.

Latest commit

 

History

History
57 lines (43 loc) · 2.62 KB

10104.md

File metadata and controls

57 lines (43 loc) · 2.62 KB
contributors
rogerluan

Overview

Overview of the data flow when requesting Siri to play a song via HomePod:

  • The device must be connected to the same network as the HomePod.
  • The device doesn't need to be physically near the person who is speaking.
  • Any app supporting SiriKit Media Intents today will be able to use this capability with no additional changes.
  • Supported options:
    • Play media
      • Music, audiobooks, podcasts, radio, meditation, and more.
    • Add to playlist or library
    • Show affinity (e.g. like/dislike)
  • "Add to playlist" and "like/dislike" actions will use voice recognition to identify the user, and the user's primary device (as configured on Find My) will be used to perform the action.

Example requests

Example code to resolve intents

class IntentHandler: INExtension, INPlayMediaIntentHandling {
    // INPlayMediaIntent methods
    func resolveMediaItems(for intent: INPlayMediaIntent, with completion: @escaping ([INPlayMediaMediaItemResolutionResult]) -> Void) {
        guard intent.mediaSearch?.mediaType != .genre else {
            return completion([INPlayMediaMediaItemResolutionResult.unsupported(forReason: .unsupportedMediaType) ])
        }
        if intent.mediaSearch?.mediaName == "push it" {
            let item = INMediaItem(identifier: "sample", title: "Push it", type: song, artwork: nil)
            return completion(INPlayMediaMediaItemResolutionResult.successes(with: [item]))
        }
        completion([INPlayMediaMediaItemResolutionResult.unsupported()])
    }
}

When handling intent, you can return two types of responses, .handleInApp, which will instruct the system to start the app and play in the background, and .continueInApp, which does the same in foreground. To offer a better experience, handle the request in backgroud using .handleInApp since it doesn't require the user to unlock their phone.

Make sure your app responds all intents as fast as possible. Requests will timeout after 10 seconds.

Related Sessions