[英]iPhone SDK - How to disable the volume indicator view if the hardware buttons are pressed?
Is there a way to prevent the volume indicator view form showing if you press the volume up/down hardware buttons? 有没有办法阻止音量指示器视图窗体显示您是否按下音量增大/减小硬件按钮?
It's needed for a demo app only. 它仅用于演示应用程序。 So the method don't need to be App Store safe.
因此该方法不需要是App Store安全的。
It works like that: 它的工作方式如下:
eg 例如
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, the presence of a MPVolumeView inhibits the display of the volume indicator overlay. IIRC,MPVolumeView的存在禁止显示音量指示器覆盖。 Try sticking it the relevant view and seeing if this is the case.
尝试坚持相关视图,看看是否是这种情况。
Then you can try various tricks to make it effectively invisible: 然后你可以尝试各种技巧使其有效隐形:
All of these are theoretically detectable by MPVolumeView, but I suspect some of them will work. 所有这些在理论上都可以被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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.