-1

動画ファイルは問題なく起動します。完了ボタンはビデオ コンテンツを閉じません。理由がわからない?また、早送りおよび巻き戻しボタンを押すと、黒い画面が表示されます。通知機能を正しく使用していないと思いますか?

import Foundation
import UIKit
import MediaPlayer

class VideoViewController: UIViewController {

var moviePlayer:MPMoviePlayerController!

@IBAction func videoLaunch(sender: AnyObject) {
    playVideo()
}
func playVideo() {
let path = NSBundle.mainBundle().pathForResource("MyVideo", ofType:"mp4")
let url = NSURL.fileURLWithPath(path!)
moviePlayer = MPMoviePlayerController(contentURL: url)
if let player = moviePlayer {
player.view.frame = self.view.bounds
moviePlayer?.controlStyle = MPMovieControlStyle.Fullscreen
player.prepareToPlay()
self.view.addSubview(player.view)

}
}


override func viewDidLoad() {
    super.viewDidLoad()

    NSNotificationCenter.defaultCenter().addObserver(
        self,
        selector: "moviePlayBackDidFinish:",
        name: MPMoviePlayerPlaybackDidFinishNotification,
        object: moviePlayer)


    func moviePlayBackDidFinish(notification: NSNotification){
        self.view.removeFromSuperview()
    }



    }
}
4

2 に答える 2

1

プレーヤー ビューをサブビューとして追加しています。完了ボタンを押した後、削除 (removeFromSuperview) する必要があります。通知を使用して、再生の終了をリッスンします。

NSNotificationCenter.defaultCenter().addObserver(
self,
selector: "moviePlayBackDidFinish:",
name: MPMoviePlayerPlaybackDidFinishNotification,
object: moviePlayer)

および moviePlayBackDidFinish:

func moviePlayBackDidFinish(notification: NSNotification){
  // remove from superview
}
于 2015-03-06T14:40:38.610 に答える