更改设备音量

发布于 2025-01-04 12:26:15 字数 153 浏览 1 评论 0原文

我正在开发一个 Iphone/Ipod 应用程序,其中使用 AVAudioPlayer。我正在通过滑块更改音频音量,该滑块可以正常工作,但现在我必须通过按设备加号和减号按钮来更改(增加/减少)滑块,而不是自己更改滑块。当我按下设备的加号/减号按钮时,不知道控件去哪里了?有谁知道吗,欢迎帮忙。

I am developing an Iphone/Ipod Application, in which I am using AVAudioPlayer. I am changing volume of audio through slider, which works correctly, but now I have to change(increase/decrease) slider by pressing the device plus and minus button instead of changing slider by myself. When I press plus/minus button of device, don't know where the control goes? Does anybody know, feel free to help.

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

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

发布评论

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

评论(3

听风念你 2025-01-11 12:26:15

如何访问硬件音量控制器?

全局系统卷(包括应用程序的卷)由 iPhone 操作系统处理,应用程序无法访问。

以下是链接,请阅读此处
希望它能帮助你:)

How do I access the hardware volume controller?

Global system volume, including your application's volume, is handled by iPhone OS and is not accessible by applications.

Here is link kindly read it here
Hope it will help you :)

无所的.畏惧 2025-01-11 12:26:15

我不太清楚这个问题,但您似乎想要在系统音量变化时收到通知?如果是这样,这是可能的,我希望我正确理解你的问题。以下怎么样:

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(volumeChanged:)
     name:@"AVSystemController_SystemVolumeDidChangeNotification"
     object:nil];
}

- (void)volumeChanged:(NSNotification *)notification
{
    float volume =
    [[[notification userInfo]
      objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"]
     floatValue];

    // Do stuff with volume
}

我从 这里,桑迪的回答。

The question isn't entirely clear to me, but it seems you're wanting a notification when the system volume changes? If so, this is possible, I hope I understand your question correctly. How about the following:

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(volumeChanged:)
     name:@"AVSystemController_SystemVolumeDidChangeNotification"
     object:nil];
}

- (void)volumeChanged:(NSNotification *)notification
{
    float volume =
    [[[notification userInfo]
      objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"]
     floatValue];

    // Do stuff with volume
}

I grabbed this from here, Sandy's answer.

月野兔 2025-01-11 12:26:15

猛击并感谢大家!我已经搜索过了。这对于 MPMusicPlayer 有效,但对于 AVAudioPlayer 无效。
你可以做到的。

MPMusicPlayerController *_musicController = [MPMusicPlayerController iPodMusicPlayer];

但对于 AVAudioPlayer 来说不是这样,

AVAudioPlayer *_audioController = [AVAudioPlayer iPodMusicPlayer];

Slam and thanks all! I have searched on it. This is valid for MPMusicPlayer, but not for AVAudioPlayer.
You can do it.

MPMusicPlayerController *_musicController = [MPMusicPlayerController iPodMusicPlayer];

But not this for AVAudioPlayer,

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