Search code examples
swiftyoutubeswift3tvostvos10

Unable to open YouTube URL to be played on YouTube tvOS Application


Question:

How do I open a YouTube URL (from my tvOS Application) to the YouTube tvOS Application?

Description:

My url fits the youtube url scheme indicated by apple. The prints I get when I run this (on the actual apple tv device) is as follows:

  1. "Can open shared application url."
  2. "tvOS 10.0 detected"
  3. "Result... false"

So for some reason it's telling me that I'm able to open the url, but then when I attempt to open it. Nothing happens (except for that last print ( see 3. above ))

    let url = URL(string: "https://www.youtube.com/watch?v=smOp5aK-_h0")
    if UIApplication.shared.canOpenURL(url){
        print("Can open shared application url.")
        if #available(tvOS 10.0, *) {
            print("tvOS 10.0 detected")

            UIApplication.shared.open(url){res in
                print("Result..." + String(res))
            }
        } else {
            // Fallback on earlier versions
            UIApplication.shared.openURL(url)
        }
    }

Youtube URL Scheme:

Native app URL strings:

http://www.youtube.com/watch?v=VIDEO_IDENTIFIER http://www.youtube.com/v/VIDEO_IDENTIFIER


Solution

  • While the methods do exist to open a URL in a shared application, it does not seem to be supported (by YouTube?) as of right now.

    The best I was able to do was to open YouTube Apple Tv App, but it is unable to play the video I wanted.