Search code examples
iosobjective-cavaudioplayermpmusicplayercontrollermpvolumeview

How to get the volume of the music/audio playing on an IOS device?


I am trying to get the volume of the music playing on an IOS device, but not the system volume. I'm not sure if "music volume" is the right term though. You can have a constant system volume when a song is playing but the music will still sound louder and softer at points (the volume of the music - "music volume" - varies).

I've seen this question that mentions how to change the music volume in the question description, but this was deprecated in IOS 7. The docs suggest using MPVolumeView, but this seems like it is used to get/change the system volume and not the music volume.

Is there any way to get the music volume in IOS 7+? Sorry if I missed something obvious in the docs.

Edit: The app will not be playing the music, but will be obtaining information about music playing in the Music app.


Solution

  • You can't do what you're asking to do with music playing from the Music app, as the sound does not belong to you. If you play the sound yourself with an AVAudioPlayer you can use its peakPowerForChannel method.