我的视频会在我的应用中的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)}
}
答案 0 :(得分:3)
要解决此问题,我已将40%
添加到' doneButtonClick'功能。然后我再次将myMoviePlayerViewController.moviePlayer.stop()
添加到
myMoviePlayerViewController.moviePlayer.play()
总而言之,一个简单的修复!代码如下:
@IBAction func watchPressed(sender: AnyObject)
{self.presentMoviePlayerViewControllerAnimated(movieViewController)}
}