このようにしてみて、
1. プロパティを定義し、MPMusicPlayerController オブジェクトに合成します。
@property (nonatomic, retain) MPMusicPlayerController *musicPlayer;
@synthesize musicPlayer;
2. float 変数を 1 つ取り、
float volume_control=0;
3. 以下のように viewDidLoad メソッドで NSNotification を使用して音量を変更します。
self.musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
NSNotificationCenter* notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self
selector:@selector(handleExternalVolumeChanged:)
name:MPMusicPlayerControllerVolumeDidChangeNotification
object:self.musicPlayer];
[self.musicPlayer beginGeneratingPlaybackNotifications];
4. handleExternalVolumeChanged のメソッドを定義する: as,
- (void)handleExternalVolumeChanged:(id)notification {
volume_control = self.musicPlayer.volume;
}
5.ボリュームコントロールボタンを定義して、ボリュームを増減します。
-(IBAction)decrease_volume:(id)sender{
if (volume_control>0) {
self.musicPlayer.volume =self.musicPlayer.volume-0.1;
volume_control-=0.1;
}
}
-(IBAction)increase_volume:(id)sender{
if (volume_control<1) {
self.musicPlayer.volume =self.musicPlayer.volume+0.1;
volume_control+=0.1;
}
}
それがあなたを助けることを願っています..