0

我使用 SplitViewController 和 Swift-YouTube-Player 在应用程序中播放 youtube 视频。它在 iPhone 上完美运行,但在 iPad 上无法运行。

在 iPhone 上,当我触发播放器时,它会全屏打开 MPMoviewPLayer 并播放视频,但在 iPad 上它在后台播放我认为,我可以引导视频的声音,但视频不会出现。

我找不到解决方案。你有什么建议为什么玩家在 splitviewcontroller 下玩?

这是触发代码

        timer = NSTimer.scheduledTimerWithTimeInterval(4, target: self, selector: "alertVideo", userInfo: nil, repeats: false)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "doneButton",  name: UIWindowDidBecomeHiddenNotification, object:nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "startVideo",  name: UIWindowDidBecomeVisibleNotification , object:nil)
        let a = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
        a.dimBackground = true
        collectionView.deselectItemAtIndexPath(indexPath, animated: true)
        let cell = collectionView.cellForItemAtIndexPath(indexPath)
        let circleView : YouTubePlayerView? = (cell!.contentView.viewWithTag(10)) as? YouTubePlayerView

        circleView?.play()

这是我使用的 YouTubePLayer: https ://github.com/gilesvangruisen/Swift-YouTube-Player

4

2 回答 2

0

我的视频仍然在 iPhone 上全屏播放,但在 iPad 上没有全屏播放。我必须对 YouTubePlayer.swift 进行更改。如果您在本节中将allowInlineMediaPlayback 更改为false:

fileprivate func buildWebView(_ parameters: [String: AnyObject]) {
    webView = UIWebView()
    webView.allowsInlineMediaPlayback = false
    webView.mediaPlaybackRequiresUserAction = false
    webView.delegate = self
    webView.scrollView.isScrollEnabled = false
}

现在它将在 iPad 上全屏播放。或者至少在撰写本文时它正在工作。我希望这会有所帮助。

于 2018-05-30T22:34:18.133 回答
0

解决了这个问题。

我用YKMediaPlayerKit更改了库。我持有玩家的实例并展示它:

let youtube : YKYouTubeVideo = YKYouTubeVideo()
var videoArray : [String] = []

self.youtube.contentURL = (NSURL(string: "http://www.youtube.com/watch?v=" + videoArray[indexPath.row]))
            youtube.parseWithCompletion({ (error) -> Void in
                if self.youtube.videos["hd720"] != nil {
                    let url = NSURL(string: (self.youtube.videos["hd720"] as! String))
                    self.timer.invalidate()
                    MBProgressHUD.hideHUDForView(self.view, animated: true)
                    let player = MPMoviePlayerViewController()
                    player.moviePlayer.contentURL = url
                    self.presentMoviePlayerViewControllerAnimated(player)
                    player.moviePlayer.play()
                } else if self.youtube.videos["medium"] != nil {
                    let url = NSURL(string: (self.youtube.videos["medium"] as! String))
                    self.timer.invalidate()
                    MBProgressHUD.hideHUDForView(self.view, animated: true)
                    let player = MPMoviePlayerViewController()
                    player.moviePlayer.contentURL = url
                    self.presentMoviePlayerViewControllerAnimated(player)
                    player.moviePlayer.play()
                } else if self.youtube.videos["small"] != nil {
                    let url = NSURL(string: (self.youtube.videos["small"] as! String))
                    self.timer.invalidate()
                    MBProgressHUD.hideHUDForView(self.view, animated: true)
                    let player = MPMoviePlayerViewController()
                    player.moviePlayer.contentURL = url
                    self.presentMoviePlayerViewControllerAnimated(player)
                    player.moviePlayer.play()
                } else {
                    let refreshAlert = UIAlertController(title: "Error", message: "Video Not Found!", preferredStyle: UIAlertControllerStyle.Alert)
                    presentViewController(refreshAlert, animated: true, completion: nil)
                }
于 2015-12-14T13:13:10.380 回答