If you want to increase the volume of iphone in a specific app and then reduce it to it's current volume. The following code might get helpful:- (NOTE:Include FrameWork: MediaPlayer.framework )
-(void)exampleFuctionSample{
NSLog(@"");
[self increaseVolume];
// Code
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(reduceVolumeToCurrent) userInfo:nil repeats:NO ]; // Timer will help you delay so that you can play increase volume
}
-(void)increaseVolume{
NSLog(@"Entered Set Volume");
float currentVolume=[MPMusicPlayerController applicationMusicPlayer].volume;
NSLog(@"Current volume is %f",[MPMusicPlayerController applicationMusicPlayer].volume);
float maxVolume = 1.0;
[[MPMusicPlayerController applicationMusicPlayer] setVolume:maxVolume];
}
-(void)reduceVolumeToCurrent{
NSLog(@"reduceVolumeToCurrent");
[[MPMusicPlayerController applicationMusicPlayer]setVolume:currentVolume];
}
0 Comment(s)