音量アップ/ダウンハードウェアボタンを押した場合に音量インジケータービューフォームが表示されないようにする方法はありますか?
デモアプリにのみ必要です。したがって、メソッドはAppStoreで安全である必要はありません。
それはそのように機能します:
例えば
NSString *url = [[NSBundle mainBundle]
pathForResource:@"silent" ofType:@"mp3"];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:[NSURL URLWithString:url]];
[moviePlayer play];
MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:
CGRectMake(0, 0, 1, 1)] autorelease];
[self.view addSubview:volumeView];
[self.view sendSubviewToBack:volumeView];
IIRC、MPVolumeViewの存在は、ボリュームインジケーターオーバーレイの表示を禁止します。関連するビューを貼り付けて、これが当てはまるかどうかを確認してみてください。
次に、さまざまなトリックを試して、効果的に非表示にすることができます。
これらはすべてMPVolumeViewで理論的に検出可能ですが、一部は機能すると思います。
- (void)viewDidLoad
{
[super viewDidLoad];
//get current volume level
oldVolume= [[MPMusicPlayerController applicationMusicPlayer] volume];
//hide volume indicator
MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:
CGRectMake(0, 0, 1, 1)] autorelease];
musicController=[MPMusicPlayerController applicationMusicPlayer];
[self.view addSubview:volumeView];
[self.view sendSubviewToBack:volumeView];
[NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(volume) userInfo:nil repeats:YES];
}
- (void)volume
{
if ([musicController volume]>oldVolume || [musicController volume]<oldVolume) {
[musicController setVolume:oldVolume];
// do some stuff here and the volume level never changes, just like volume action in camera app
}
}