我想知道如何使用AssetLibrary检索视频格式并在uilabel上显示?我在论坛上阅读使用ALAssetPropertyRepresentations但我刚刚丢失。请帮忙吗?
答案 0 :(得分:0)
我不确定你的“格式”是什么意思,但是这段代码会显示视频的UTI(基本上是文件类型)和任何元数据。
ALAssetsGroupEnumerationResultsBlock assetEnumerator = ^(ALAsset *asset, NSUInteger index, BOOL *stop) {
if(asset != nil) {
ALAssetRepresentation* representation = [asset defaultRepresentation];
NSLog(@"UTI = %@", [representation UTI]);
NSLog(@"Metadata = %@", [representation metadata]);
}
};
ALAssetsLibraryGroupsEnumerationResultsBlock assetGroupEnumerator = ^(ALAssetsGroup *group, BOOL *stop) {
if(group != nil) {
[group setAssetsFilter:[ALAssetsFilter allVideos]];
[group enumerateAssetsUsingBlock:assetEnumerator];
}
};
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:^(NSError *error) {
NSLog(@"A problem occured. %@", error);
}];
[library release];
(代码经here修改。)
如果您已拥有资产,则更新标签的代码如下所示:
myLabel.text = [[myAsset defaultRepresentation] UTI];