如果您按下音量增大/减小硬件按钮,有没有办法阻止显示音量指示器视图?
仅限演示应用程序。因此该方法不需要是App Store安全的。
答案 0 :(得分:4)
它的工作原理如下:
e.g
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];
答案 1 :(得分:2)
然后你可以尝试各种技巧使其有效隐形:
所有这些理论上都可以通过MPVolumeView检测到,但我怀疑它们中的一些会起作用。
答案 2 :(得分:1)
- (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
}
}