How to play Vimeo video in iOS Swift?

I am creating an iOS application that uses Vimeo to play videos. I was wondering what the best way is to show the Vimeo video in iOS Swift.

I found that when you click on an image, the placeholder image will be hidden, but the video will not play directly. In addition, all elements of the Vimeo interface are visible. I know that you need to give Vimeo loans, so it goes without saying that I show the Vimeo logo at the bottom of the video. Is it possible to hide all the elements of Vimeo web player?

Sources where I can find more information will be enjoyable. If you have any questions, let me know! Thanks in advance.

+6
source share
5

, , - WKWebView UIWebView. :

  1. WKWebView View Controller.

  2. Vimeo ( "" , ).

    enter image description here

  3. " " Vimeo Share, .

  4. :

    let webView = WKWebView(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height))
    self.view.addSubview(webView)
    
    let embedHTML="<html><head><style type=\"text/css\">body {background-color: transparent;color: black;}</style><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes\"/></head><body style=\"margin:0\"><div><iframe src=\"//player.vimeo.com/video/139785390?autoplay=1&amp;title=1&amp;byline=1&amp;portrait=0\" width=\"640\" height=\"360\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div></body></html>"
    let url = URL(string: "https://")!
    webView.loadHTMLString(embedHTML as String, baseURL:url )
    webView.contentMode = UIViewContentMode.scaleAspectFit
    
+5

Swift HCVimeoVideoExtractor, URL- mp4, AVPlayer . - Vimeo .

let url = URL(string: "https://vimeo.com/254597739")!
HCVimeoVideoExtractor.fetchVideoURLFrom(url: url, completion: { ( video:HCVimeoVideo?, error:Error?) -> Void in                
    if let err = error {                    
       print("Error = \(err.localizedDescription)")                    
       return
    }

    guard let vid = video else {
        print("Invalid video object")
        return
    }

    print("Title = \(vid.title), url = \(vid.videoURL), thumbnail = \(vid.thumbnailURL)")

    if let videoURL = vid.videoURL[.Quality540p] {
        let player = AVPlayer(url: videoURL)
        let playerController = AVPlayerViewController()
        playerController.player = player
        self.present(playerController, animated: true) {
            player.play()
        }
    }                            
})
+3

, , AVKit AVFoundation:

let url: URL! = URL(string: "https://01-lvl3-pdl.vimeocdn.com/01/3355/3/91775232/243724947.mp4?expires=1498547278&token=073f7b03877a8ed3c8029")
let player: AVPlayer = AVPlayer(url: url)
let controller: AVPlayerViewController = AVPlayerViewController()

controller.view.translatesAutoresizingMaskIntoConstraints = false
controller.player = player

// Add `controller` to your view somehow

player.play()

, , - ( https://vimeo.com/91775232).

URL (: https://01-lvl3-pdl.vimeocdn.com/01/3355/3/91775232/243724947.mp4?expires=1498547278&token=073f7b03877a8ed3c8029).

, .

+2

Swift 4 WKWebView :

import WebKit

@IBOutlet webKitView: WKWebView!

WebView:

if yourVimeoLink.lowercased().contains("vimeo.com") {
            let url: NSURL = NSURL(string: yourVimeoLink)
            webKitView.contentMode = UIViewContentMode.scaleAspectFit
            webKitView.load(URLRequest(url: url as URL))

}

! :)

0
source
import AVFoundation
import AVKit

let videoURL = "https://vimeo.com/blablabla/whatevertheURLis"

func playExternalVideo() {
    let videoURL = NSURL(string: self.videoURL)
    let player = AVPlayer(url: videoURL as! URL)
    let playerViewController = AVPlayerView()

    playerViewController.player = player
}

Remember to add the AVKit Player View and give it the AVPlayerView class. As for the Vimeo deal, it should play without Vimeo UI Controls. See this video for more information. https://www.youtube.com/watch?v=fhD7hXrpExE

-3
source

Source: https://habr.com/ru/post/1661732/


All Articles