I try to add some basic information in videos under Info Box, but I don't know how to add or update it?
Anyone knows how to do it?
On
If you need to download image asynchronously -like in my case-, here is what I'm using for it:
Objective-C
#import <AFNetworking/UIKit+AFNetworking.h>
@property (strong, nonatomic) NSMutableArray<AVMetadataItem*>* metaData;
// Build title item
AVMutableMetadataItem* titleMetadataItem = [[AVMutableMetadataItem alloc] init];
titleMetadataItem.locale = NSLocale.currentLocale;
titleMetadataItem.key = AVMetadataCommonKeyTitle;
titleMetadataItem.keySpace = AVMetadataKeySpaceCommon;
titleMetadataItem.value = self.currentVideoData.Title;
[_metaData addObject:titleMetadataItem];
// Build description item
AVMutableMetadataItem* descriptionMetadataItem = [[AVMutableMetadataItem alloc] init];
descriptionMetadataItem.locale = NSLocale.currentLocale;
descriptionMetadataItem.key = AVMetadataCommonKeyDescription;
descriptionMetadataItem.keySpace = AVMetadataKeySpaceCommon;
descriptionMetadataItem.value = description;
[_metaData addObject:descriptionMetadataItem];
self.player.currentItem.externalMetadata = _metaData;
NSString* artwork = @"https://Your_image_path"
__weak typeof(self) weakSelf = self;
if (![artwork isEqualToString:@""]) {
// Build artwork item
UIImageView* imgArtwork = [UIImageView new];
imgArtwork.contentMode = UIViewContentModeScaleAspectFit;
[imgArtwork
setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:artwork]]
placeholderImage:nil
success:^(NSURLRequest* _Nonnull request,
NSHTTPURLResponse* _Nullable response,
UIImage* _Nonnull image) {
[weakSelf.metaData
addObject:[weakSelf metadataArtworkItemWithImage:image]];
weakSelf.player.currentItem.externalMetadata = _metaData; // re-setting meta data here...
}
failure:nil];
}
//...
// same method of @beyowulf
- (AVMetadataItem*)metadataArtworkItemWithImage:(UIImage*)image {
AVMutableMetadataItem* item = [[AVMutableMetadataItem alloc] init];
item.value = UIImagePNGRepresentation(image);
item.dataType = (__bridge NSString * _Nullable)(kCMMetadataBaseDataType_PNG);
item.identifier = AVMetadataCommonIdentifierArtwork;
item.extendedLanguageTag = @"und";
return item.copy;
}
it works like a charm.
TVJS
You can set metadata properties directly on the
MediaItemobject that you instantiate.For more information see here and here.
AVKit
Swift
You should add
externalMetadatato yourAVPlayerItem. To do this you can add these two helper functions that Apple has provided in their WWDC session:The first one will take an identifier, the type of metadata you would like to add, and the value for that type and return an optional
AVMetadataItemThe other takes aUIImageand returns the same thing.Now you can say something like the following when you update your
AVPlayerItem:Which gives you something like:
You can find more information here.
Objective-C