MPMoviePlayerDidExitFullscreenNotification 问题 - iOS8 - swift

Posted

技术标签:

【中文标题】MPMoviePlayerDidExitFullscreenNotification 问题 - iOS8 - swift【英文标题】:MPMoviePlayerDidExitFullscreenNotification issue - iOS8 - swift 【发布时间】:2014-12-19 16:24:03 【问题描述】:

我已经实现了一个 MPMoviePlayerViewController,它可以正确加载视频并关闭播放器。但是当用户在 MPMoviePlayerViewController 中点击“完成”时,我无法收到通知。 我认为这是一个ios8的问题。这是代码:

func fullscreenVideo()
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "doneFull:", name: MPMoviePlayerDidExitFullscreenNotification, object: nil)

    let url = NSURL(fileURLWithPath: self.videoPath)
    self.fullscreenPlayer = MPMoviePlayerViewController(contentURL: url)        
    self.fullscreenPlayer!.view.frame = CGRect(x: 0.0, y: 0.0, width: 0.0, height: 0.0)
    self.fullscreenPlayer!.moviePlayer.view.frame = CGRect(x: 0.0, y: 0.0, width: 0.0, height: 0.0)
    self.fullscreenPlayer!.moviePlayer.controlStyle = MPMovieControlStyle.Fullscreen
    self.fullscreenPlayer!.moviePlayer.repeatMode = MPMovieRepeatMode.One
    self.fullscreenPlayer!.moviePlayer.allowsAirPlay = false
    self.fullscreenPlayer!.moviePlayer.fullscreen = true
    self.fullscreenPlayer!.moviePlayer.prepareToPlay()
    self.presentViewController(self.fullscreenPlayer!, animated: true, completion: nil)
    self.fullscreenPlayer!.moviePlayer.play()


func doneFull(notification:NSNotification)
    // When user tap "Done" the player closes but this function is not called.
    println("CALLED") // Never called

有什么建议吗?

【问题讨论】:

【参考方案1】:
NSNotificationCenter.defaultCenter().addObserver(self, 
selector: "doneFull:", 
name: MPMoviePlayerDidExitFullscreenNotification, 
object: self.fullscreenPlayer!.moviePlayer)

尝试用 self.fullscreenPlayer!.movi​​ePlayer

替换您的对象 nil

在这种情况下你必须设置对象参数。

【讨论】:

以上是关于MPMoviePlayerDidExitFullscreenNotification 问题 - iOS8 - swift的主要内容,如果未能解决你的问题,请参考以下文章