1

下面的代码显示了一个视频。它在 swift 2 中完美运行,但在 swift 3 xcode 中表明 MPMoivePlayerController 代码已被淘汰。我只是希望我的视频像在 swift 2 中一样显示在 swift 3 中。

import UIKit 
import AVFoundation
import AVKit
import MediaPlayer


class video: UIViewController {

var moviePlayer : MPMoviePlayerController!


   override func viewDidLoad() {
    super.viewDidLoad()


    let path = Bundle.main.path(forResource: "jxdo", ofType:"mp4")
    let url = URL(fileURLWithPath: path!)
    self.moviePlayer = MPMoviePlayerController(contentURL: url)
    if let player = self.moviePlayer {
        player.view.frame = CGRect(x: 67, y: 75, width: self.view.frame.size.width/2, height: self.view.frame.size.height / 5)
        player.view.sizeToFit()
        player.scalingMode = MPMovieScalingMode.aspectFit
        player.isFullscreen = false
        player.controlStyle = MPMovieControlStyle.default
        player.movieSourceType = MPMovieSourceType.file
        player.repeatMode = MPMovieRepeatMode.none

        self.view.addSubview(player.view)
4

1 回答 1

1

MPMoviePlayerController 已被弃用,应改为使用 AVPlayerViewController。在 Apple 的文档页面上查看更多信息https://developer.apple.com/reference/mediaplayer/mpmovieplayercontroller

此外,此线程可能有助于开始转换为较新的 api:How to load MPMoviePlayerController contentUrl asynchronous when loading view?

于 2016-10-25T20:49:13.880 回答