【问题标题】:SWIFT: MediaPlayer - Done Button doesn't do anythingSWIFT:MediaPlayer - 完成按钮不做任何事情
【发布时间】:2016-01-01 15:17:48
【问题描述】:

所以我的以下代码运行良好!适用于任何想要在 SWIFT 中制作视频的人。问题是,视频结束后,它仍保留在视频中。即使按下 Done 也没有任何反应......

如何将视频关闭回现有的视图控制器之一?

class ViewController: UIViewController {

var moviePlayer : MPMoviePlayerController?
override func viewDidLoad() {
    super.viewDidLoad()
    playVideo()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func playVideo() {

    //Get the Video Path
    //You need to put this in Project->Target->copy bundle resource for this to work
    let videoPath = NSBundle.mainBundle().pathForResource("Quizzes", ofType:"mov")

    //Make a URL from your path
    let url = NSURL.fileURLWithPath(videoPath!)

    //Initalize the movie player
    moviePlayer = MPMoviePlayerController(contentURL: url)

    if let player = moviePlayer {

        //Make the player scale the entire view
        player.view.frame = self.view.bounds
        player.scalingMode = .AspectFill

        //Add it as a subView to your currentView
        self.view.addSubview(player.view)

        //Play the video
        player.prepareToPlay()

    }
    else {
        print("Movie player couldn't be initialized")
    }
}

【问题讨论】:

    标签: ios swift video media-player mplayer


    【解决方案1】:

    您已将其添加为子视图

    self.view.addSubview(player.view)

    您还需要删除它,该代码在哪里? 播放完毕请使用 removeFromSuperview。

    【讨论】:

      猜你喜欢
      • 2017-12-31
      • 2019-07-13
      • 2014-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多