Issue with onPlayPauseCommand - tvOS

I am having issues with the following code. Basically I have the following code and I want it to pause the music that is playing however it seems to not fire. I am wondering what is the correct way to get tvOS to recognise the play pause button on the remote control.

.onPlayPauseCommand(perform: {
    MusicPlayer.shared.player?.pause()
    
})

FULL CODE

//
//  ContentView.swift
//  DRN1
//
//  Created by Russell Harrower on 10/10/20.
//

import SwiftUI
import AVKit



struct ContentView: View {
    @State var showingDetail = false
    
    @State var showDetail = String(false)
    var body: some View {
       
                            VStack{
                                
                                 Text("Interactive Radio").font(.headline).bold().multilineTextAlignment(.leading)
                                 Text(showDetail)
                                 Text("Hello, World!")
                                    .onLongPressGesture {
                                        print("Long pressed!")
                                    }
                                                       
                                 Spacer()
                                                       
                           }
                         
                         
            
                            
        .onAppear {
         //   self.navigationViewStyle(StackNavigationViewStyle())
            MusicPlayer.shared.startBackgroundMusic(url: "http://stream.radiomedia.com.au:8006/stream", type: "radio")
            print(self.showingDetail)
               
        }
                            
                       
        .onPlayPauseCommand(perform: {
            MusicPlayer.shared.player?.pause()
            
        })
    
    }
    

}


struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
Terms of Service

Privacy Policy

Cookie Policy