tvOS: AVPlayerViewController.transportBarCustomMenuItems not working

Hi guys,

Setting AVPlayerViewController.transportBarCustomMenuItems is not working on tvOS. I still see 2 icons for Audio and Subtitles.

	let menuItemAudioAndSubtitles = UIMenu(
		image: UIImage(systemName: "heart")
	)
	playerViewController.transportBarCustomMenuItems = [menuItemAudioAndSubtitles]

WWDC 2021 video is insufficient to make this work. https://developer.apple.com/videos/play/wwdc2021/10191/

The video doesn't say what exactly I need to do. Do I need to disable subtitle options?

	viewController.allowedSubtitleOptionLanguages = []

This didn't work and I still see the default icon loaded by the player. Do I need to create subclass of AVPlayerViewController?

I just want to replace those 2 default icons by 1 icon as a test, but I was unsuccessful after many hours of work. Is it mandatory to define child menu items to the main item? Or do I perhaps need to define UIAction?

The documentation and video are insufficient in providing guidance how to do that. I did something like this before, but that was more than 3 years ago and audi and subtitles was showing at the top of the player screen as tabs, if I rememebr correctly.

Is transportBarCustomMenuItems perhaps deprecated? Is it possible that when loading AVPlayerItem and it detects audi and subtitles in the stream, it automatically resets AVPlayerViewController menu? How do I suppress this behavior?

I'm currently loading AVPlayerViewController into SwiftUI interface. Is that perhaps the problem? Should I write SwiftUI player overlay from scratch?

Thanks, Robert

I need to replace Subtitle and Audio icons by one icon which will combine Audio and Subtitles, then add a few other icons, for opening a list of channels so user could switch channel, opening EPG and other icons with specific actions.

WWDC 2022 video didn't help me either https://developer.apple.com/videos/play/wwdc2022/10147/

BTW: Why I can only set metadata to display a few specific things, like title and subtitle and I cannot add any view I want, change position od "LIve" badge, etc. AVPlayerViewController.contentViewController property is readonly. I have to traverse view hierarchy and hierarchy of view controllers of AVPlayerViewController and hack those existing views, which is tricky, may not be reliable for future tvOS releases, may require more maintenance and use of #ifdef or #if available() or whatever. Isn't there a better approach?

Here is an example:

tvOS: AVPlayerViewController.transportBarCustomMenuItems not working
 
 
Q