PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 29, 2022

[FIXED] How to edit video's info in Apple TV?

 September 29, 2022     apple-tv, tvml, tvos, tvos9.1     No comments   

Issue

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?

enter image description here


Solution

TVJS

You can set metadata properties directly on the MediaItem object that you instantiate.

var mediaItem = new MediaItem("video", videoURL);
mediaItem.title = "My Title";
mediaItem.subtitle = "My Subtitle";
mediaItem.artworkImageURL = someURL;
mediaItem.description = "My description";

For more information see here and here.

AVKit

Swift

You should add externalMetadata to your AVPlayerItem. To do this you can add these two helper functions that Apple has provided in their WWDC session:

    func metadataItem(identifier : String, value : protocol<NSCopying,
        NSObjectProtocol>?) -> AVMetadataItem? {
        if let actualValue = value {
            let item = AVMutableMetadataItem()
            item.value = actualValue
            item.identifier = identifier
            item.extendedLanguageTag = "und" // undefined (wildcard) language
            return item.copy() as? AVMetadataItem
        }
        return nil
    }
    
    func metadataArtworkItem(image: UIImage) -> AVMetadataItem? {
        let item = AVMutableMetadataItem()
        // Choose PNG or JPEG
        item.value = UIImagePNGRepresentation(image)
        item.dataType = kCMMetadataBaseDataType_PNG as String
        item.identifier = AVMetadataCommonIdentifierArtwork
        item.extendedLanguageTag = "und"
        return item.copy() as? AVMetadataItem
    }

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 AVMetadataItem The other takes a UIImage and returns the same thing.

Now you can say something like the following when you update your AVPlayerItem:

let videoURL = NSURL(string: "http://devstreaming.apple.com/videos/wwdc/2016/506ms2tv71tcduwp3dm/506/hls_vod_mvp.m3u8")
self.player = AVPlayer(URL: videoURL!)
let playerItem = self.player?.currentItem
var allItems: [AVMetadataItem] = [AVMetadataItem]()
allItems.append(self.metadataItem(AVMetadataCommonIdentifierTitle, value: "AVKit on tvOS")!)
allItems.append(self.metadataItem(AVMetadataCommonIdentifierDescription, value: "2016 WWDC session AVKit on tvOS where adding metadata to AVPlayerItem is covered")!)
if let image = UIImage(named: "Poster"), let artworkItem = metadataArtworkItem(image)
{
    allItems.append(artworkItem)
}
playerItem?.externalMetadata = allItems

Which gives you something like:

enter image description here

You can find more information here.

Objective-C

- (AVMetadataItem *)metadataItemWithIdentifier:(NSString *)identifier value:(id<NSObject, NSCopying>) value
{
    AVMutableMetadataItem *item = [[AVMutableMetadataItem alloc]init];
    item.value = value;
    item.identifier = identifier;
    item.extendedLanguageTag = @"und";
    return [item copy];
}

- (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;
}

// Add this code where you update the AVPlayerItem
NSURL *videoURL = [NSURL URLWithString:self.detailItem.urlString];
playerViewController.player = [AVPlayer playerWithURL:videoURL];
self.player = playerViewController.player;
AVPlayerItem *playerItem = self.player.currentItem;
NSMutableArray <AVMetadataItem *> *allItems = [NSMutableArray new];
[allItems addObject:[self metadataItemWithIdentifier:AVMetadataCommonIdentifierTitle value:@"AVKit on tvOS"]];
[allItems addObject:[self metadataItemWithIdentifier:AVMetadataCommonIdentifierDescription value:@"2016 WWDC session AVKit on tvOS where adding metadata to AVPlayerItem is covered"]];
[allItems addObject:[self metadataArtworkItemWithImage:[UIImage imageNamed:@"Poster"]]];
playerItem.externalMetadata = allItems;


Answered By - beyowulf
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing