如果您按下音量增大/减小硬件按钮,有没有办法防止显示音量指示器视图?
仅演示应用程序需要它。所以该方法不需要是 App Store 安全的。
它是这样工作的:
例如
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
}
}