0

MPVolumeView はカスタマイズの余地があまりないので避けようとしています。基本的には、ユーザーが発信者の声の音量を事前に設定できるようにするボリューム コントロールを実装したいと考えています。これがその画面です。のように見える:

ここに画像の説明を入力

UIButton を使用してボリュームの増減ボタンを作成したいのですが、IB でターゲット アクション メカニズムを次のように実装することを考えています。

- (IBAction)increaseVolume:(id)sender
{
    [someVolumeObject setVolume:[systemVolume volume] + 1];
}

- (IBAction)decreaseVolume:(id)sender
{
    [someVolumeObject setVolume:[systemVolume volume] - 1];
}

システム ボリューム要素を抽出し、この方法で (基本的に MPVolumeView を使用せずに) インクリメントできるクラスがあるかどうかを知っている人はいますか?

4

1 に答える 1

1

このようにしてみて、

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;
   }
  }

それがあなたを助けることを願っています..

于 2012-12-24T05:49:49.767 に答える