有什么方法可以获取现有 AVAsset 的资源名称?
Any way to get the resource name of an existing AVAsset?
我有兴趣获取 AVAsset
的资源名称(又名文件名),特别是 mp4 视频。资产是用资源名称创建的,我只是想在将来只有 AVAsset
实例时获得相同的字符串资源。在这种情况下,如何从资产中获取 "my-video"
?
AVAsset(URL: NSBundle.mainBundle().URLForResource("my-video", withExtension: "mp4")!)
我能够获取资产的 title
,但这并不总是与资源名称相同。并且文件名不在资产的公共元数据中。
var title = ""
for metadataItem in asset.commonMetadata {
if metadataItem.commonKey == "title" {
title = metadataItem.value as! String
}
}
您可以使用 AVURLAsset
.
NSURL *url = [[NSBundle mainBundle] URLForResource:@"my-video" withExtension:@"mp4"];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
NSLog(@"filename: %@", asset.URL.lastPathComponent);
抱歉,我对Swift了解不多,可能是:
let url:NSURL = NSBundle.mainBundle().URLForResource("my-video", withExtension: "mp4")!
let asset:AVURLAsset = AVURLAsset.init(URL: url, options: nil)
let filename:NSString = asset.URL.lastPathComponent!
print(filename)
在Swift 4
let assetURL = avAsset as! AVURLAsset
let name = assetURL.url.lastPathComponent
我有兴趣获取 AVAsset
的资源名称(又名文件名),特别是 mp4 视频。资产是用资源名称创建的,我只是想在将来只有 AVAsset
实例时获得相同的字符串资源。在这种情况下,如何从资产中获取 "my-video"
?
AVAsset(URL: NSBundle.mainBundle().URLForResource("my-video", withExtension: "mp4")!)
我能够获取资产的 title
,但这并不总是与资源名称相同。并且文件名不在资产的公共元数据中。
var title = ""
for metadataItem in asset.commonMetadata {
if metadataItem.commonKey == "title" {
title = metadataItem.value as! String
}
}
您可以使用 AVURLAsset
.
NSURL *url = [[NSBundle mainBundle] URLForResource:@"my-video" withExtension:@"mp4"];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
NSLog(@"filename: %@", asset.URL.lastPathComponent);
抱歉,我对Swift了解不多,可能是:
let url:NSURL = NSBundle.mainBundle().URLForResource("my-video", withExtension: "mp4")!
let asset:AVURLAsset = AVURLAsset.init(URL: url, options: nil)
let filename:NSString = asset.URL.lastPathComponent!
print(filename)
在Swift 4
let assetURL = avAsset as! AVURLAsset
let name = assetURL.url.lastPathComponent