Getting video from Asset Catalog using On Demand ressources

大城市里の小女人 提交于 2019-12-05 12:30:32

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.

Refer this link for more info

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

The problem is putting the mp4 in the asset catalogue. Resources don't have to be in the asset catalogue to be accessed as on demand resources.

Move your assets out of the catalogue in to the workspace and tag them then use the bundle property of the NSBundleResourceRequest

import UIKit

class ViewController: UIViewController {
    var bundleRequest = NSBundleResourceRequest(tags: [])

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let tags: Set<String>  = ["odr"]
        bundleRequest = NSBundleResourceRequest(tags: tags)

        bundleRequest.beginAccessingResourcesWithCompletionHandler { (error:NSError?) -> Void in
            if let e = error {
                print(e)
                return
            }
            NSOperationQueue.mainQueue().addOperationWithBlock({ () -> Void in
                if let url = self.bundleRequest.bundle.URLForResource("tokyo", withExtension: "mp4") {
                    //use the url to play the video with avplayer
                }

            })
        }
    }

}

Sure it can the movie will end up getting stored in a data file.

NSDataAsset

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