Volume slider not working in AVPlayer

Hello,

I'm facing an issue with the volume slider in AVPlayer. Despite setting the volume property and mute property to false, the volume slider does not work as expected.

Initially, the volume is muted with the slider set to the minimum. If I change the volume, when I release the slider, it returns to the minimum and the mute icon remains active. However, if I set it to maximum, the setting remains and the icon changes. However, the video volume never changes and remains at the value set in the code.

Here is the code I am using:

var player: AVPlayer! var playerController: AVPlayerViewController!

   override func viewDidLoad() {
       super.viewDidLoad()
       
       player = AVPlayer(url: URL(fileURLWithPath: Bundle.main.path(forResource: "video", ofType: "mp4")!))
       
       player.volume = 0.5
       player.isMuted = false
       
       playerController = AVPlayerViewController()
       playerController.player = player
       playerController.view.frame = self.view.frame
       
       addChild(playerController)
       view.addSubview(playerController.view)
       playerController.view.frame = view.bounds
       playerController.didMove(toParent: self)
       
       player.play()
   }

Can someone please help me resolve this issue? Any assistance would be greatly appreciated.

Thank you.

Volume slider not working in AVPlayer
 
 
Q