斯威夫特的电影播放器

时间:2014-10-18 13:27:30

标签: ios xcode swift viewcontroller movieplayer

我正在迅速做一个简单的电影播放器​​。我在ViewController中有这样的播放器。

enter image description here

我希望这样。

enter image description here

此处的代码

import UIKit
import MediaPlayer

class DetailViewController: UIViewController {

var moviePlayer:MPMoviePlayerController!

override func viewDidLoad() {
super.viewDidLoad()

var url:NSURL = NSURL(string: "http://jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v")

moviePlayer = MPMoviePlayerController(contentURL: url)

moviePlayer.view.frame = CGRect(x: 16, y: -100, width: 600, height: 400)

moviePlayer.view.sizeToFit()

self.view.addSubview(moviePlayer.view)

moviePlayer.fullscreen = true

moviePlayer.controlStyle = MPMovieControlStyle.Embedded

}

}

2 个答案:

答案 0 :(得分:2)

继续Dharmesh回复,请更新

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

然后将根据设备屏幕大小进行调整。

希望它有所帮助!

答案 1 :(得分:1)

试试这个,因为它对我有用:

moviePlayer.view.frame = CGRect(x: 0, y: 0, width: 320, height: 568)