我在这里玩过 YouTube-Player-iOS-Helper
:https://github.com/youtube/youtube-ios-player-helper
但我不知道如何从某一秒开始嵌入到 iOS App 中的视频,有什么想法吗?
如你所见,我试过了
"start": 100
,但是会崩溃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: "layback 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/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |