iPhone SDK - How to disable the volume indicator view if the hardware buttons are pressed?

后端 未结 3 1594
猫巷女王i
猫巷女王i 2020-12-30 15:43

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 do

3条回答
  •  半阙折子戏
    2020-12-30 16:25

    It works like that:

    • play a silent file
    • add a volume View to your main view
    • send the view to back

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

提交回复
热议问题