gpt4 book ai didi

ios - 我如何使用 Youtube iOS API 查找、转到某一秒?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:19:33 25 4
gpt4 key购买 nike

我在这里玩过 YouTube-Player-iOS-Helper:https://github.com/youtube/youtube-ios-player-helper

但我不知道如何从某一秒开始将视频嵌入到 iOS 应用程序中,有什么想法吗?

如你所见,我已经尝试过了

  1. 添加一个 HTML5 键值对 "start": 100,但它崩溃了
  2. 并尝试在视频加载后搜索,pv.seekToSeconds(100, allowSeekAhead: true) 但也没有效果

===

class ViewController: UIViewController {

@IBOutlet weak var pv: YTPlayerView!
override func viewDidLoad() {
super.viewDidLoad()


pv.loadWithVideoId("M7lc1UVf-VE", playerVars: ["controls": 0, "playsinline": 1, "autohide": 1, "showinfo": 0, "modestbranding": 1]) //, "start": 100
NSNotificationCenter.defaultCenter().addObserver(self, selector: "receivedPlaybackStartedNotification:", name: "Playback started", object: nil)
}

func receivedPlaybackStartedNotification(notification: NSNotification) {

pv.seekToSeconds(100, allowSeekAhead: true)
}
}

最佳答案

您需要等待 playerViewDidBecomeReady 委托(delegate)被调用。

在 Swift 中,这是:

class MyViewVc: UIViewController, YTPlayerViewDelegate {

@IBOutlet weak var ytPlayer: YTPlayerView!

override func viewDidLoad() {
super.viewDidLoad()

self.ytPlayer.delegate = self

self.ytPlayer.load(withVideoId: "M7lc1UVf-VE")
}

func playerViewDidBecomeReady(_ playerView: YTPlayerView) {
self.ytPlayer.seek(toSeconds: 100, allowSeekAhead: true)
}
}

关于ios - 我如何使用 Youtube iOS API 查找、转到某一秒?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26827202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com