1 Reply
      Latest reply on Feb 18, 2020 11:36 PM by vadimfromchisinau
      DiegoHenriquez-youi Level 1 Level 1 (0 points)


        I am setting up a simple test app on TVOS to airplay the audio of a video to a Apple HomePod. The audio plays great but it seem that I cannot control the volume using the TVOS remote. I would assume that would work right out of the box but it does not.

        So the question is am I supposed to create something or do something with `AVAudioSession`?
        Note: I am not using AVPlayerViewController(which using this works). I am using AVPlayerLayer.

        Audio Session Setup(AppDelegate.m

        - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
            // Override point for customization after application launch.
            AVAudioSession* audioSession = [AVAudioSession sharedInstance];
            [audioSession setCategory:AVAudioSessionCategoryPlayback mode:AVAudioSessionModeMoviePlayback routeSharingPolicy:AVAudioSessionRouteSharingPolicyLongForm options:0 error:nil];
            [audioSession setActive:YES error:nil];
            return YES;


        Player Creation(ViewController.m)

        - (void)viewDidLoad {
            [super viewDidLoad];
            // Do any additional setup after loading the view.
            NSString *assetURI = @"https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8";
            NSURL *urlRequest = [[NSURL alloc] initWithString:assetURI];
            // Create an AVPlayer, passing it the HTTP Live Streaming URL.
            _player =  [AVPlayer playerWithURL:urlRequest];
            // Has to be set `NO` for audio of the video to airplay.
            _player.allowsExternalPlayback = NO;
            _playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player];
            _playerLayer.videoGravity = AVLayerVideoGravityResize;
            // Provide a way to select route
            AVRoutePickerView* view = [[AVRoutePickerView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
            [self.view.layer addSublayer:_playerLayer];
            [self.view addSubview:view];


        Any suggestion would be apretiated.
        Thanks in advance!