Swift에서 dismissMoviePlayerViewControllerAnimated
에 대한 게시물이없는 것 같아서 일을 시작하겠습니다.dismissMoviePlayerViewControllerAnimated가 Swift에서 작동하지 않습니다.
나는 테이블 셀을 가지고 있는데, 길게 누르면 비디오가 표시됩니다. 동영상이 끝나면 내 목표는 사용자를 다시 테이블보기로 이동시키는 것입니다. 마지막 부분은 작동하지 않는 비트입니다.
여기에 도움을 주시면 매우 감사하겠습니다. Objective-C에서 Apple docs 및 이에 관한 게시물을 읽었습니다. 대답은 dismissMoviePlayerViewControllerAnimated
, UIViewController의 메소드를 실행하는 것으로 보이지만 작동하지 않습니다.
import UIKit
import MediaPlayer
class ViewController: UIViewController {
var moviePlayer:MPMoviePlayerController!
@IBOutlet weak var longPressView: UIView!
let longPressRec = UILongPressGestureRecognizer()
func longPressedView() {
playVideo()
}
func videoHasFinishedPlaying(notification: NSNotification){
println("Video finished playing")
self.dismissMoviePlayerViewControllerAnimated()
// not returning me to the ViewController
}
func playVideo() {
// get path and url of movie
let path = NSBundle.mainBundle().pathForResource("IMG_8602", ofType:"MOV")
let url = NSURL.fileURLWithPath(path!)
moviePlayer = MPMoviePlayerController(contentURL: url)
// construct the views
moviePlayer.view.frame = self.view.bounds
self.view.addSubview(moviePlayer.view)
moviePlayer.fullscreen = true
// remove controls at top and bottom of video
moviePlayer.controlStyle = MPMovieControlStyle.None
// add event observer for videoHasFinsihedPlaying
NSNotificationCenter.defaultCenter().addObserver(self, selector: "videoHasFinishedPlaying:",
name: MPMoviePlayerPlaybackDidFinishNotification, object: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
longPressRec.addTarget(self, action: "longPressedView")
longPressView.addGestureRecognizer(longPressRec)
longPressView.userInteractionEnabled = true
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
감사합니다. 모든'MPMoviePlayerController'를'MPMoviePlayerViewController's로 변경했습니다. 그것도'moviePlayer.moviePlayer.controlStyle = MPMovieControlStyle.None'을 호출해야합니다. (두 개의 moviePlayer가 있습니다. 첫 번째는 var 이름이고, 두 번째는'MPMoviePlayerViewController' 메서드입니다. –