Implementing video view in the Storyboard(在 Storyboard 中实现视频视图)
问题描述
我想构建一个简单的视频应用程序,它可以查看用户添加的视频表单 youtube 链接.我没有找到VideoView",我的意思是如果图像视图用于图像,那么 UIView 用于视频.
I want to build simple video app thats views a video form youtube links thats users add. I didn't find "VideoView" I mean If image view is for image what is UIView for videos.
推荐答案
原库中没有执行视频查看功能的对象.但是您可以在项目中导入 MediaPlayer
框架并以编程方式添加它.
There is no object in the original library that performs video viewing function. But you can import the MediaPlayer
framework in your project and add it programmatically.
这是一个 Swift 示例
Here is a Swift example
import MediaPlayer
class Step1ViewController: UIViewController {
var moviePlayer: MPMoviePlayerController?
override func viewDidLoad() {
super.viewDidLoad()
playVideo()
}
func playVideo() {
let videoView = UIView(frame: CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.bounds.width, self.view.bounds.height))
let pathToEx1 = NSBundle.mainBundle().pathForResource("myVideoFile", ofType: "mp4")
let pathURL = NSURL.fileURLWithPath(pathToEx1!)
moviePlayer = MPMoviePlayerController(contentURL: pathURL)
if let player = moviePlayer {
player.view.frame = videoView.bounds
player.prepareToPlay()
player.scalingMode = .AspectFill
videoView.addSubview(player.view)
}
self.view.addSubview(videoView)
}
}
至于进一步的定制和应用通知,它有很多内置的可能性.所以看看吧.
As for further customisations and app notifications it has a bunch of in-build possibilities. So check it out.
这篇关于在 Storyboard 中实现视频视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Storyboard 中实现视频视图
基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01