Similar to this question asking about how to play YouTube videos on tvOS, I'd like to play Vimeo videos in the app I'm building. However, as explained here, regular web views (which is how I do things in iOS) are out.
How would I go about playing a Vimeo video on tvOS assuming I knew the URL to the video page but not the URL to the raw .mp4 file?
To play Vimeo videos on your TV, we recommend using one of the platforms listed above. Vimeo apps on these platforms are no longer supported: Some smart TV platforms provide web browsers that can access standard websites. The Vimeo website and video player are not tested in TV web browser environments and are not supported.
There are lots of ways to watch Vimeo videos on devices other than your computer — to start, native Vimeo apps are available for these popular app platforms and devices: Search for “Vimeo” in the Roku channel store or visit the app listing here.
Search for “Vimeo” on the Amazon Fire TV device, or visit the app listing here. Cast from the Vimeo Android or iOS mobile apps, learn more here. Note: for more information on using showcases for custom channels on Roku and Amazon Fire, visit this page.
Simply put, Vimeo takes care of all the technology needs and customer service, giving creators more time to focus on content creation, growing their brand, and connecting with their audience. I landed on Vimeo as an OTT service because you really felt like you were talking to people, not automated emails.
Well, apparently, there is no way to play a Vimeo video in a WebView, because tvOS SDK doesn't have a WebView. The only option we have is AVPlayer, but it requires a direct URL to a video, and Vimeo won't give us direct video URLs for free. Right now, the only possible way is to purchase Vimeo's PRO membership ($199 per year at the moment) and retrieve direct video URLs via Vimeo's API.
EDIT: as nickv2002 noted, this approach will give you direct URLs only to YOUR OWN videos. Thi means, that even with Vimeo PRO you can't just take any video on Vimeo and get a direct URL for it.
Using this pod, tvOS can play vimeo contents, Install
pod 'YTVimeoExtractor'
and
import YTVimeoExtractor
And use this function to play the video
func playVimeoVideo(videoId: String)
{
YTVimeoExtractor.shared().fetchVideo(withVimeoURL: "https://vimeo.com/video/\(videoId)", withReferer: nil) { (video:YTVimeoVideo?, error:Error?) in
if let streamUrls = video?.streamURLs
{
var streamURL: String?
var streams : [String:String] = [:]
for (key,value) in streamUrls {
streams["\(key)"] = "\(value)"
print("\(key) || \(value)")
}
if let large = streams["720"]
{
streamURL = large
}
else if let high = streams["480"]
{
streamURL = high
}
else if let medium = streams["360"]
{
streamURL = medium
}
else if let low = streams["270"]
{
streamURL = low
}
if let url = streamURL
{
let videoURL = NSURL(string: url)
let player = AVPlayer(url: videoURL! as URL)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.present(playerViewController, animated: true) {
playerViewController.player!.play()
}
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With