下面的代码显示了一个视频。它在 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)