如何在代码中判断用户是否已“锁定音量”在他们的设置菜单中

发布于 2024-11-27 11:08:00 字数 308 浏览 3 评论 0原文

目前,我将音量设置为最大值,然后检查音量是否为最大值或更低的值。如果它的值较低,则用户必须在其系统上设置音量锁定。

这工作正常,但我想知道是否有一些方法可以调用,或者属性可以检查,它可以在代码中免费告诉我这一点?我一直在网上寻找如何做到这一点,但我似乎找不到任何东西。提前致谢!

编辑:事实证明,我之前设置最大音量然后检查音量是否较低以查看是否有音量锁定的方法在该设备上不起作用。似乎音量是通过音量锁定来缩放的,而不是仅仅被切断。

现在我完全陷入了困境。我是否可以使用任何私有方法或属性来检测这一点?

Currently, I'm setting the volume to max, and then checking if the volume is at max, or a lower value. If it's at a lower value, then the user must have a Volume Lock on their system.

This works fine, but I'm wondering if there is some method to call, or property to check which tells me this in code for free? I've been looking online as to how to do this, but I can't seem to find anything. Thanks in advance!

Edit: It turns out that my previous method of setting the max volume and then checking if it's lower to see if there is a Volume lock does not work on the device. It seems as though the volume is scaled with the Volume lock, instead of just being cut off.

Now I'm completely stuck on this. Is there even any private methods or properties that I can use in order to detect this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

少女的英雄梦 2024-12-04 11:08:00

我想你想问的是iphone是否有音量限制。我一直在寻找答案,但找不到答案。这是一种检查音量大小的方法,希望对您有所帮助。

在 XIB 中,您可以添加一个滑块来检查音量级别,因此基本上您可以判断它是否静音,并了解音量级别。为了更多地了解这个类,这里​​是链接 http:// /blog.stormyprods.com/2008/09/proper-usage-of-mpvolumeview-class.html 但首先尝试一下:

以下代码将创建类似音量条的东西。

  - (void)viewDidLoad {
            // create a frame for MPVolumeView image
     CGRect frame = volumeViewHolder.bounds; // CGRectMake(0, 5, 180, 0);
     volumeView = [[[MPVolumeView alloc] initWithFrame:frame] autorelease];
     [volumeView sizeToFit];
     [volumeViewHolder addSubview:volumeView];

     for (UIView *view in [volumeView subviews]){
      if ([[[view class] description] isEqualToString:@"MPVolumeSlider"]) {
       volumeViewSlider = view;
      }
     }
     [[NSNotificationCenter defaultCenter] addObserver:self 
          selector:@selector(volumeChanged:) 
          name:@"AVSystemController_SystemVolumeDidChangeNotification" 
          object:nil];
    }
    - (void) volumeChanged:(NSNotification *)notify
    {
    [volumeViewSlider setValue:[[[notify userInfo] objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"] floatValue]];
    }

我听说,出于某种原因,如果您使用某个类别(我的示例中的类别),苹果不允许您销售应用程序,但我对此不太确定,我会仔细检查并确保您是“允许”使用它。但代码应该可以工作。

I think what you are asking for is to find out if the iphone has a cap on the volume limit. I have looked for the answer but could not find one. Here is a way just to check the volume level, hope this helps.

In your XIB you can add a slider to check what the volume level is at, so basically you can tell if it is silent, and know the level of the volume. For more understanding of this class, here's the link http://blog.stormyprods.com/2008/09/proper-usage-of-mpvolumeview-class.html but try this first:

The following code will create something like a volume bar.

  - (void)viewDidLoad {
            // create a frame for MPVolumeView image
     CGRect frame = volumeViewHolder.bounds; // CGRectMake(0, 5, 180, 0);
     volumeView = [[[MPVolumeView alloc] initWithFrame:frame] autorelease];
     [volumeView sizeToFit];
     [volumeViewHolder addSubview:volumeView];

     for (UIView *view in [volumeView subviews]){
      if ([[[view class] description] isEqualToString:@"MPVolumeSlider"]) {
       volumeViewSlider = view;
      }
     }
     [[NSNotificationCenter defaultCenter] addObserver:self 
          selector:@selector(volumeChanged:) 
          name:@"AVSystemController_SystemVolumeDidChangeNotification" 
          object:nil];
    }
    - (void) volumeChanged:(NSNotification *)notify
    {
    [volumeViewSlider setValue:[[[notify userInfo] objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"] floatValue]];
    }

I heard that for some reason apple doesn't allow you to sell an app if you use a certain class (the one in my example) but I'm not too sure about this, I would double-check and make sure that you are 'allowed' to use it. But the code should work.

紙鸢 2024-12-04 11:08:00

这个问题有很多答案,但它们似乎都在某种程度上违反了苹果的指导方针或应用商店管理者,因为苹果没有提供官方的方法来做到这一点。

然而,您可以利用一个功能来找出这一点,即当设备静音时,操作系统根本不会播放声音 - 因此,如果您播放 800 毫秒的声音文件,并计算播放时间(如果小于) 800ms即可推断静音开关打开。

我建议使用无声的 800ms 声音文件来使用此技巧,这样用户就不会突然遇到意外的声音。

请参阅此处激发我灵感的文章: http ://inforceapps.wordpress.com/2009/07/08/detect-mute-switch-state-on-iphone/

另外,您可能想要使用 Audio Toolbox 可以简单地做到这一点并保证正在使用静音开关。

There are many answers to this problem but they all seem to have fallen foul of Apple's guidelines or App Store curators at some point as Apple don't provide an official way to do this.

However one feature you can utilise to find this out is that when a device is muted then the OS will not play the sound at all - so if you play a 800ms sound file and you time how long it takes to play if it is less than 800ms then you can infer that the mute switch is on.

I would recommend to use a silent 800ms sound file to use this trick so that the user is not suddenly confronted with an unexpected sound.

See here for the article that inspired me: http://inforceapps.wordpress.com/2009/07/08/detect-mute-switch-state-on-iphone/

In addition you might want to use the Audio Toolbox to do this simply and guarantee that the mute switch is being used.

若相惜即相离 2024-12-04 11:08:00

考虑将音量设置为最大,然后录制输出通道,并播放短音 - 然后将录制的样本的峰值与不存在音量限制器的已知样本进行比较。如果 iPad 在录音访问输出音量之前缩放输出音量,则此功能将起作用。

我希望我有更多关于如何记录输出的信息,但我对此没有太多个人经验。精通记录输入的人应该能够为您指出正确的方法。

Consider setting the volume to max, then recording the output channel, and playing a short tone - then compare the peak of that recorded sample to a known sample where the volume limiter is not present. This will work if the iPad scales the output volume before recording gets access to it.

I wish I had more info on how to record the output, but I don't have much personal experience with it. Somebody who is versed in recording input should be able to point you the right way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文