While AirPlaying, MPVolumeView snaps to different volume when I play my app media

I have an app that plays sound files stored locally. I'm using a single SwiftUI view with a MPVolumeView so the user can control system volume from the player in my app. When I'm playing the sound file on the iPhone, my volume slider operates as expected. When I AirPlay to my AppleTV, the volume slider still works to control the volume, but when I hit play in my app, the volume snaps to a different value, but actual sound volume doesn't change. Control still works. Flipping to control center, I see a volume mismatch between system volume and the MPVolumeView.

Here's the code that I use to put the slider in my app.

    struct VolumeSlider: UIViewRepresentable {
        func makeUIView(context: Context) -> MPVolumeView {
            let vv = MPVolumeView(frame: .zero)
            vv.showsVolumeSlider = true
            vv.setVolumeThumbImage(UIImage() ,for: UIControl.State.normal)
            return vv
        }
        
        func updateUIView(_ uiView: MPVolumeView, context: Context) {
            // No need to update the view in this case
        }
    }

I'm using AVFoundation and AVAudioPlayer to playback the sound file. I'm using MediaPlayer to tell MPNowPlayingInfoCenter the track info and AlbumArt. Audio control via control center works perfectly. Does the same if I target iOS 16 or 17.

Is this a bug with the MPVolumeView or the way I added it to the app?

Answered by Engineer in 807514022

Hello @SlyKnight, thank you for your post. Our engineering teams need to investigate this issue, as resolution may involve changes to Apple's software. I'd greatly appreciate it if you could open a bug report, and post the FB number here once you do. Bug Reporting: How and Why? has tips on creating your bug report.

I'm now confident this issue is iOS. I was able to get a similar bug using Apple Music app. Comparing the slider in the control center of iOS18 and the volume show in the now playing view. changing volume in the now playing view doesn't affect the volume shown on the slider, and volume up physical button click jumps the now playing volume to the control center volume.

Accepted Answer

Hello @SlyKnight, thank you for your post. Our engineering teams need to investigate this issue, as resolution may involve changes to Apple's software. I'd greatly appreciate it if you could open a bug report, and post the FB number here once you do. Bug Reporting: How and Why? has tips on creating your bug report.

While AirPlaying, MPVolumeView snaps to different volume when I play my app media
 
 
Q