Tvos AVPlayerViewController how to display subtitle tab in swipedown menu

In tvOS , in the menu that appears when the user goes through a remote control that shows “subtitles, audio and information” in other movie applications, how do I create another tab with buttons?

Below is my code:

 AVMutableMetadataItem *titleMetadataItem = [[AVMutableMetadataItem alloc] init]; titleMetadataItem.locale = NSLocale.currentLocale; titleMetadataItem.key = AVMetadataCommonKeyTitle; titleMetadataItem.keySpace = AVMetadataKeySpaceCommon; titleMetadataItem.value = @"The Title"; NSArray *externalMetadata = [[NSArray alloc] initWithObjects:titleMetadataItem, nil]; _player.player.currentItem.externalMetadata = externalMetadata; 

Can someone please tell me how can I create buttons in the AVPlayerViewController drop-down menu so that the user can switch between turning subtitles on or off? I do not have srt files built into the video. Instead, I have a separate subtitle parser and I display it on a shortcut. I was able to get a section of information to show the text, but is there any way to add buttons?

OR how can I add a subtitle option to a video? This does not work: _player.requiresFullSubtitles = YES;

Thanks!

+7
objective-c tvos avplayerviewcontroller
source share
1 answer

AVPlayerViewController only downloads subtitles if they are embedded in HLS streams, and this is also the only legitimate way to display the Subtitles tab in the swipedown menu.

I built a utility for dynamically adding VTT subtitles to HLS streams (m3u8) called ACHLSCaptioningServer ( https://github.com/acotilla91/ACHLSCaptioningServer ).

Note. If you only have access to SRT files, you need to find a way to convert SRT to VTT.

How to use:

 NSURL *origStreamURL = your_original_stream-url; NSURL *vttFileURL = your_vtt_file_url; NSURL *streamURL = [[ACHLSCaptioningServer sharedInstance] getCaptionedHLSStreamFromStream:origStreamURL vttURL:vttFileURL]; // // play stream // AVURLAsset *videoAsset = [[AVURLAsset alloc] initWithURL:streamURL options:nil]; AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:videoAsset]; AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem]; AVPlayerViewController *avPlayerController = [[AVPlayerViewController alloc] initWithNibName:nil bundle:nil]; [avPlayerController setPlayer:player]; [avPlayerController.view setFrame:self.view.frame]; [self addChildViewController:avPlayerController]; [self.view addSubview:avPlayerController.view]; [avPlayerController didMoveToParentViewController:self]; 
0
source share

All Articles