【问题标题】:Get Vimeo video duration in Swift 5 [duplicate]在 Swift 5 中获取 Vimeo 视频持续时间 [重复]
【发布时间】:2021-01-19 00:18:52
【问题描述】:

我想知道如何在 Swift 中获取视频持续时间我已经设法通过使用视频链接从 Vimeo 显示视频,然后将其提取出来。现在有什么办法可以让我知道那个视频的时间吗?谢谢。

这是我的代码:

let url = URL(string: "https://vimeo.com/[video_id]")!
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[.Quality1080p] {
        let player = AVPlayer(url: videoURL)
        let playerController = AVPlayerViewController()
        playerController.player = player
        self.present(playerController, animated: true) {
            player.play()
        }
    }                            
}

【问题讨论】:

  • 您尝试获取持续时间的部分在哪里?

标签: ios swift vimeo


【解决方案1】:

一旦您获得带有if let videoURL 的视频网址,您就可以从中创建一个AVAsset 并获取其持续时间。详情请见here

let asset = AVAsset(url: videoURL)
let duration = asset.duration
let durationTime = CMTimeGetSeconds(duration)
let minutes = Double(durationTime / 60)

【讨论】:

  • 如果您知道某事是重复的,请不要回答:投票关闭作为重复。
  • @matt 好的,抱歉 :(
  • 没问题,谢谢指出重复!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-26
  • 2019-04-08
  • 1970-01-01
相关资源
最近更新 更多