gpt4 book ai didi

iphone - 即使在静音模式下也能在 iPhone 上播放声音

转载 作者:行者123 更新时间:2023-12-02 23:56:31 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





iPhone - Is it possible to override silent mode or have a recursive alert sound with push notification? [closed]

(3 个回答)


3年前关闭。




我想制作一个在 iPhone 处于静音模式时创建声音、音乐或系统声音的应用程序。在静音模式下是否可以播放任何类型的声音,无论是音乐还是系统音?

最佳答案

这是不可取的,但我是谁说你不能这样做。您可能有充分的理由播放声音。

如果您使用的是 Audio Session ,则包括 <AVFoundation/AVFoundation.h>在文件的开头和

[[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryPlayback
error: nil];

应该做的伎俩。请注意,如果您播放音乐或声音,则 iPod 播放将暂停。

完成此操作后,可能在某个播放声音的类的初始化中,您可以像这样实例化声音:
// probably an instance variable: AVAudioPlayer *player;
NSString *path = [[NSBundle mainBundle] pathForResource...];
NSURL *url = [NSURL fileURLWithPath:path];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url];

完成后,您可以随时使用它:
[player play]; // Play the sound
[player pause]; // Pause the sound halfway through playing
player.currentTime += 10 // skip forward 10 seconds
player.duration // Get the duration

和其他好东西。查找 AVAudioPlayer类引用。

关于iphone - 即使在静音模式下也能在 iPhone 上播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15034719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com