gpt4 book ai didi

xcode - Swift - 无法关闭 MPMoviePlayerViewController

转载 作者:IT王子 更新时间:2023-10-29 05:44:29 24 4
gpt4 key购买 nike

我有一个视频在我的应用程序的 MPMoviePlayerController 中打开。除了应该关闭播放器的 Done 按钮外,一切都很好。第一次播放视频时,Done 按钮效果很好。但是,如果您在观看视频时暂停它,然后在第二次尝试播放视频时点击 Done,则 Done 按钮不起作用。我在这里做了一个屏幕录像,让它更容易理解: http://1drv.ms/1Jcdodc

有人能帮忙吗?

这是我正在使用的代码:

import UIKit
import MediaPlayer

class MainContent: UIViewController {

//Movie Player variables
var movieViewController : MPMoviePlayerViewController?
var movieplayer : MPMoviePlayerController!


override func viewDidLoad() {

super.viewDidLoad()

//Video Player setup
NSNotificationCenter.defaultCenter().addObserver(self, selector: "doneButtonClick:", name: MPMoviePlayerPlaybackDidFinishNotification, object: nil)

var url = NSURL(string: "http://jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v")!
movieViewController = MPMoviePlayerViewController(contentURL: url)

}



func doneButtonClick(sender:NSNotification?){
let value = UIInterfaceOrientation.Portrait.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
}

//when watch button is pressed, present the movie player
@IBAction func watchPressed(sender: AnyObject)
{self.presentMoviePlayerViewControllerAnimated(movieViewController)}

}

最佳答案

为了解决这个问题,我将 myMoviePlayerViewController.movi​​ePlayer.stop() 添加到“doneButtonClick”函数中。然后我再次将 myMoviePlayerViewController.movi​​ePlayer.play() 添加到

@IBAction func watchPressed(sender: AnyObject)
{self.presentMoviePlayerViewControllerAnimated(movieViewController)}

}

总而言之,这是一个简单的修复!代码如下:

import UIKit
import MediaPlayer

class MainContent: UIViewController {

//Movie Player variables
var movieViewController : MPMoviePlayerViewController?
var movieplayer : MPMoviePlayerController!


override func viewDidLoad() {

super.viewDidLoad()

//Video Player setup
NSNotificationCenter.defaultCenter().addObserver(self, selector: "doneButtonClick:", name: MPMoviePlayerPlaybackDidFinishNotification, object: nil)

var url = NSURL(string: "http://jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v")!
movieViewController = MPMoviePlayerViewController(contentURL: url)

}

func doneButtonClick(sender:NSNotification?){
let value = UIInterfaceOrientation.Portrait.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
movieViewController?.moviePlayer.stop()
}

@IBAction func watchPressed(sender: AnyObject){
self.presentMoviePlayerViewControllerAnimated(movieViewController)
movieViewController?.moviePlayer.play()
}
}

关于xcode - Swift - 无法关闭 MPMoviePlayerViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30939570/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com