Override ringer volume in iPhone apps

I created an application that plays many sounds in a simple way:

AudioServicesPlaySystemSound(someSoundID);

When I use the device’s volume buttons to increase or decrease the volume, what I actually change is the volume of the phone ringing. Therefore, if you reduce it and exit the application, your phone will ring silently ...

Is there an easy way to override this and actually change the size of my application?

+4
source share
2 answers

, , , . , , , .

AVFoundation , , ( ), AVAudioPlayer, "prepareToPlay" "...

, ( ): :

#import <AVFoundation/AVFoundation.h>

@interface MainViewController : UIViewController {
    AVAudioPlayer *volumeOverridePlayer;
}

@property (nonatomic, retain) AVAudioPlayer *volumeOverridePlayer;

:

    @synthesize volumeOverridePlayer;

- (void)viewDidLoad
{
    [super viewDidLoad];

    volumeOverridePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"something" ofType:@"caf"]] error:nil];
    [volumeOverridePlayer prepareToPlay];
//...
}

! , , dealloc.

+5

, Apple, . 1. OS/ /. 2. . , , , . , .

!

+2

All Articles