In tvOS
, in the menu that is being displayed when a user swipes down on the remote, that shows "subtitles, audio & info" on other movie apps, how to 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 a buttons in the swipe down menu of an AVPlayerViewController
so that a user can toggle between turning off or turning on the subtitles? I do not have the srt files
embedded in the video. Instead I have a separate subtitle parser
and I display it on a label. I was able to get info section to show with text but is there any way to add buttons?
OR
how I can add a subtitle option to the video?
This does not work:
_player.requiresFullSubtitles = YES;
Thanks!
The AVPlayerViewController
only loads subtitles if they're embedded in the HLS streams, and that is also the only legal way to show the "Subtitles" tab on the swipe down menu.
I built a utility for dynamically adding VTT subtitles to HLS (m3u8) streams called ACHLSCaptioningServer
(https://github.com/acotilla91/ACHLSCaptioningServer).
Note: If you only have access to SRT files you'll need to find a way to convert SRTs to VTTs.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With