iosswiftios9corespotlight

Core Spotlight API - kUTTypeAudio play button in search result


Is it possible with the new Search API to have a play button in the search result cell?

I tried something like this:

let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeAudio as String)
...
attributeSet.contentType = kUTTypeAudio as String
attributeSet.contentURL = NSURL(fileURLWithPath: dataPath)

In the keynote they searched for a movie and got a result with a play button. Maybe this is possible with later betas?


Solution

  • Yes and no. Review the documents, that's always my favorite place to go with questions :). As far as Core Spotlight, if it is a viable feature, it's not publicly annotated on the documents Apple has provided us, so far. As you can see in the keynote, they were discussing Rich Results (dialing a phone number, playing a movie etc) during the index you spotted contained the Rich Result, more specifically during the Web Markup API discussion, which is why you saw what you saw in the keynote. They annotate there are two ways for you to accomplish playing a movie or audio:

    You can also use schema markup to enable actions within rich results. For example, you might let users dial a phone number, get directions to an address, or play audio or video by integrating markup similar to the code shown here:

    <!-- Two ways to enable playing audio or video. ->
    
    <!-- Using Open Graph markup: ->
    <meta property="og:video:url" content="https://example.com/videofile">
    
    <!-- Using Schema.org markup: ->
    <div itemscope itemtype=
       "http://schema.org/AudioObject">
       <meta itemprop="contentUrl"
    content="http://example.com/x.m4a" />
    </div>
    

    SOURCE