IPhone SDK. How to turn off the display of the volume indicator if the hardware buttons are pressed?

Is there a way to prevent the appearance of the volume level indicator when I press the hardware volume up / down buttons?

This is only needed for the demo application. Therefore, the method should not be safe in the App Store.

+5
source share
3 answers

IIRC, the presence of MPVolumeView blocks the display of the overlay of the volume indicator. Try sticking it to the appropriate look and see if it is.

Then you can try various tricks to make it invisible:

  • Make it hidden (or do hidden browsing).
  • ( ) 0 0.01 .
  • (, )
  • .
  • clipToBounds = ON
  • volumeView.layer.mask ( , ) CALayer. volumeView.userInteractionEnabled = .

MPVolumeView, , .

+2

:

 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];
+4
- (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
   }
}
+1
source

All Articles