使用随需应变资源从资产目录中获取视频 [英] Getting videos from Assets catalog using On Demand resources

查看:59
本文介绍了使用随需应变资源从资产目录中获取视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将标签"tokyo"归因于我的.mp4视频,并将其设置为在应用安装过程中安装的视频.

I attributed the tag "tokyo" to my .mp4 video, and set it as installed during the app installation.

最初,我使用的是从资源中加载路径,但是现在有所不同,因为它位于Asset目录中.

Originally, I was using a path to load it from my resources, however, now it's different because it's located in the Asset catalog.

阅读文档后,我尝试过类似的操作:

After reading the documentation, I tried something like:

NSBundleResourceRequest(tags: ["tokyo"]).beginAccessingResourcesWithCompletionHandler { (error) -> Void in
    let tokyoVideo = NSDataAsset(name: "tokyo")
}

要以NSData形式访问此视频,我可以使用:

To access this video as NSData I could use:

tokyoVideo.data

但是,我正在使用AVPlayer,它将参数作为NSURL,而不是NSData.

However, I'm using AVPlayer which takes the parameter as an NSURL, not NSData.

那我该如何获取视频的NSURL? 资产目录是否仅用于存储数据,我应该使用它来存储视频,还是有更好的选择?

So how do I get the NSURL for my video? Is the Asset catalog only for storing Data and should I be using that to store my video, or is there a better alternative?

推荐答案

我认为可以将Asset Catalog用于视频内容,它简化了图像管理.为此使用NSDataAsset.查看下表中的最后一行.

I think its possible to use Asset Catalog for video stuff, Its simplify management of images. Use NSDataAsset for it. Review the last row in below table.

请参阅下表列出了可以标记为按需资源的资源类型.

The following table lists the types of resources that can be tagged as on-demand resources.

这篇关于使用随需应变资源从资产目录中获取视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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