applicationMusicPlayer volume notification

2020-01-27 03:08发布

I am using an applicationMusicPlayer and when i try to change the volume appear the visual notification, as shown in the picture. Here the code I am using:

[MPMusicPlayerController applicationMusicPlayer] setVolume:newVolune];

Anyone knows how to hide this notification?

enter image description here

6条回答
We Are One
2楼-- · 2020-01-27 03:16

For me, on iOS 7, none of above solutions worked. Here is how I did it:

_volume = [[MPVolumeView alloc] initWithFrame: CGRectMake(-100,-100,16,16)];
_volume.showsRouteButton = NO;
_volume.userInteractionEnabled = NO;
[self.view addSubview:_volume];
[_volume release];

That is, simply set MPVolumeView's frame to an off-screen location such as (-100,-100).

查看更多
够拽才男人
3楼-- · 2020-01-27 03:28

I don't know where the docs says so, but if you add a MPVolumeView view to your app the system volume overlay goes away. Even if it is not visible:

- (void) viewDidLoad 
{
    [super viewDidLoad];
    MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame: CGRectZero];
    [self.view addSubview: volumeView];
    [volumeView release];
    ...
}

You can use the hardware volume buttons, the setVolume method or directly interact with the control (if visible) that the overlay doesn't show up.

查看更多
【Aperson】
4楼-- · 2020-01-27 03:28

Swift 3

You can hide the System MPVolumeView using

override func viewDidLoad() {
    super.viewDidLoad()
    let volumeView = MPVolumeView(frame: CGRect.zero)
    self.view.addSubview(volumeView)
  }
查看更多
别忘想泡老子
5楼-- · 2020-01-27 03:30

I had success with this in iOS 6. Although it wouldn't perform well. It caused quite a bit of lag when sliding the thumbImage. I did have to take out the last 2 lines of code in order for this to work.

[volumeView release];
    ...
查看更多
做自己的国王
6楼-- · 2020-01-27 03:36

For iOS6 I had to set an image with alpha 0 and non-zero size to the MPVolumeView's image fields in order to get the default volume change notification to disappear.

// hide the hardware volume slider
UIImage *thumb = [[UIImage alloc] initWithCIImage:[UIImage imageNamed:@"volumeHider"].CIImage scale:0.0 orientation:UIImageOrientationUp];
MPVolumeView *hwVolume = [[MPVolumeView alloc] initWithFrame:self.frame];
[hwVolume setUserInteractionEnabled:NO];
hwVolume.showsRouteButton = NO;
[hwVolume setVolumeThumbImage:thumb forState:UIControlStateNormal];
[hwVolume setMinimumVolumeSliderImage:thumb forState:UIControlStateNormal];
[hwVolume setMaximumVolumeSliderImage:thumb forState:UIControlStateNormal];
[self addSubview:hwVolume];

This made the MPVolumeView be "visible" on the screen, but invisible to the user.

查看更多
老娘就宠你
7楼-- · 2020-01-27 03:38

I encountered the same issue recently. Instead of adding the MPVolumeView to current view controller's view, I add it to the application's window once at the start of the app:

CGRect rect = CGRectMake(-500, -500, 0, 0);
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:rect];
[self.window addSubview:volumeView];

This works in both iOS 7 and 8.

查看更多
登录 后发表回答