MPMoviePlayerController SWIFT视频背景无法播放

时间:2015-02-20 21:01:17

标签: ios xcode swift ios8

我一直在尝试,但我的代码无效。有人知道为什么吗?感谢。

override func viewDidAppear(animated: Bool) {
    var url:NSURL = NSURL(string: "http://techslides.com/demos/sample-videos/small.mp4")!
    var moviePlayer = MPMoviePlayerController(contentURL: url)

    moviePlayer!.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)


    moviePlayer!.controlStyle = .None
    moviePlayer!.scalingMode = .AspectFill
    moviePlayer!.movieSourceType = .Unknown


    moviePlayer!.prepareToPlay()
    moviePlayer!.shouldAutoplay = true
    moviePlayer!.play()

    self.view.insertSubview(moviePlayer.view, atIndex:0)

}

1 个答案:

答案 0 :(得分:1)

var url:NSURL = NSURL(字符串:“http://techslides.com/demos/sample-videos/small.mp4”)!         moviePlayer = MPMoviePlayerController(contentURL:url)

    if let player = moviePlayer {
        player.view.frame = self.view.bounds
        moviePlayer?.controlStyle = MPMovieControlStyle.None
        player.prepareToPlay()
        player.scalingMode = .AspectFill
        player.repeatMode = MPMovieRepeatMode.One
        self.view.insertSubview(player.view, atIndex:0)
    }