我如何寻找,使用Youtube iOS API获得一定的时间?

时间:2014-11-09 10:29:25

标签: ios html5 youtube youtube-api youtube-javascript-api

我在YouTube-Player-iOS-Helper点击了"start": 100

但我无法弄清楚如何从某一秒开始嵌入iOS App的视频,任何想法?

如你所见,我试过

  1. 添加HTML5键值对pv.seekToSeconds(100, allowSeekAhead: true),但崩溃
  2. 并试图在视频加载后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) } } 寻找,但也没有效果
  3. ===

    {{1}}

2 个答案:

答案 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)
    }
}