我在YouTube-Player-iOS-Helper
点击了"start": 100
但我无法弄清楚如何从某一秒开始嵌入iOS App的视频,任何想法?
如你所见,我试过
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)
}
}
寻找,但也没有效果===
{{1}}
答案 0 :(得分:1)
您好我调查此库的Github示例。并且测试也尝试使用此代码段。
- (void)testSeekTo {
[[mockWebView expect] stringByEvaluatingJavaScriptFromString:@"player.seekTo(5.5, false);"];
[playerView seekToSeconds:5.5 allowSeekAhead:NO];
[mockWebView verify];
}
答案 1 :(得分:0)
您需要等待playerViewDidBecomeReady
委托被调用。
在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)
}
}