在情节提要中实现视频视图 [英] Implementing video view in the Storyboard

查看:50
本文介绍了在情节提要中实现视频视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想构建一个简单的视频应用,该应用可以查看用户添加的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.

这篇关于在情节提要中实现视频视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆