Movie Player in Swift

一曲冷凌霜 提交于 2019-12-13 09:31:39

问题


I'm doing simple movie player in swift. I have player in ViewController like this.

and i want it like this.

Here's code

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

}

}

回答1:


in continuation to Dharmesh reply, please update

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

it will then be adjusted as per device screen size.

Hope it helps!




回答2:


Try this because it's work for me:

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


来源:https://stackoverflow.com/questions/26440238/movie-player-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!