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

728 views Asked by At

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

2

There are 2 answers

0
kemicofa ghost On BEST ANSWER

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.

2
user2829898 On

Many tvOS devs would like to have an option to play YouTube content in their apps on the AppleTV, which is only possible through the YouTube app. It's up to Google to add support for URL schemes compatible with the ones available in the iOS version of the app and they don't seem motivated to make this extra effort.