Linuxmint
Linuxmint

Reputation: 4746

Adjust Volume in-App

How can I adjust the iphone volume in my app? There is a way (pandora does it) but I just don't know how to.

I mainly need to be able to set the volume to max, and then set it to nothing later.

Does anyone have any ideas or tutorials?

Thanks in advance!

Upvotes: 0

Views: 4831

Answers (2)

Dev Kanchen
Dev Kanchen

Reputation: 2352

I was looking for a way to do this for my MPMoviePlayerController, and after DAYS of searching, turns out it's just one line.

[[MPMusicPlayerController applicationMusicPlayer] setVolume:(use a value between 0.0 and 1.0)]

The catch being that your MPMoviePlayerController needs to be using the application audio session.

Note that from my testing this works ONLY for MPMoviePlayerController - I cannot be certain about the effect this has on AVAudioPlayers etc. But it's worth a shot anyway.

Edit: Oh, also. It seems kinda hacky - although it all boils down to how each component interacts with the application audio session, I'm not ACTIVELY setting any property of that sort on the applicationMusicPlayer. That setting the volume property on it also influences my MPMoviePlayerController is a lucky accident, and there really is no way to be sure this behavior won't change in a future release! /Disclaimer.

Upvotes: 3

Shawn Craver
Shawn Craver

Reputation: 1986

If you're looking for a way to allow the user to control the volume while in your app, which is what Pandora is doing, you're looking for MPVolumeView. Having used the same control myself, I'm 90% sure that is what Pandora is using.

Upvotes: 3

Related Questions