ios7 UIWebView Youtube Video

前端 未结 5 575
滥情空心
滥情空心 2021-02-04 10:33

I have a UIWebView subclass that I used to play both youtube and local videos. Worked perfectly under iOS6. In upgrading to iOS7 I\'ve encountered a problem I don\'t really kn

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-04 11:10

    YouTube has made available a framework to save us from the hassle of using a web view directly. The framework is available at: https://github.com/youtube/youtube-ios-player-helper

    All you need to do is to create a YTPlayerView view, add it to the view hierarchy with the constraints you like and load the video. Like so:

        youTubePlayer = YTPlayerView()
        youTubePlayer!.translatesAutoresizingMaskIntoConstraints = false
        contentView.addSubview(youTubePlayer!)
        youTubePlayer!.pinAllAnchors(to: contentView)
        youTubePlayer!.load(withVideoId: url.youTubeVideoId()!)
    

    Note that pinAllAnchors and youTubeVideoId are helpers I created. They are not part of the framework.

提交回复
热议问题