objective-c - 当铃声静音时,如何防止我的应用程序(使用 AVPlayer)被静音?

标签 objective-c ios audio avplayer ringtone

这个主题可能听起来很奇怪,但请继续阅读。

我正在使用 AVPlayer 播放 iPod 库中的一些声音,在插入耳机时一切正常,但当我想使用该应用程序从内置扬声器播放时,没有声音输出。 (计时器和应用程序中的其他所有内容仍然正常工作,就像会有声音输出一样。就像它只是静音一样。)

我检查了音量和静音锁,然后发现铃声被静音了。但铃声静音不会影响其他应用程序,例如 iPod 应用程序本身或 Spotify 音乐应用程序。

如何防止我的应用程序(使用 AVPlayer)在铃声静音时被静音并像其他音乐播放器应用程序一样运行?

最佳答案

您应该将应用的 Audio Session 设置为 AVAudioSessionCategoryPlayback。来自 docs :

Use this category for an application whose audio playback is of primary importance. Your audio plays even with the screen locked and with the Ring/Silent switch set to silent.

关于objective-c - 当铃声静音时,如何防止我的应用程序(使用 AVPlayer)被静音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11798664/

相关文章:

html - HTML对象嵌入音量

c - 使用c语言在linux下使用oss制作一个可以播放音频文件的程序

android - 如何将 ALSA 与 android ndk 一起使用?

ios - 如何使用 touchMoves 事件在 Objective-C 中移动使用 BezierPath 绘制的对象

ios - 在 Swift 中使用谓词

ios - 无法识别的选择器发送到实例。 NSInvalidArgumentExpectation

ios - Sprite 套件 TableView

ios - 如何在应用程序启动时以模态方式呈现 View Controller?

objective-c - UILabel 有最大高度吗?

iOS Swift - 设置开始时间和结束时间(仅限 future 时间)UIDatePicker