AVAudioSession:某些蓝牙设备在我的应用程序上无法正常工作 [英] AVAudioSession: Some Bluetooth devices are not working properly on my App

查看:227
本文介绍了AVAudioSession:某些蓝牙设备在我的应用程序上无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AVAudioSession开发一个快速的音频/视频和文字聊天iOS App。

I'm developing a swift audio/video and text chat iOS App using AVAudioSession.

每当我选择使用某些蓝牙设备时,设备上播放的声音是不是App音频流。它们仅在发送/接收消息时播放由文本聊天库发送的系统声音。它不会发生在所有蓝牙设备上,其中一些设备工作正常。在内置麦克风和扬声器的应用程序也可以正常工作。

Whenever I select to use some Bluetooth devices the sound played on the device is not the App audio stream. They play only the system sound sent by text chat library whenever messages are sent/received instead. It doesn't happen on all Bluetooth devices, on some of them everything works fine. On Builtin Mic and Speaker the App works fine too.

以下是我班级管理设备最重要的方法:

Here are the most important methods from my class to manage the device:

class MyAudioSession
{
    private var mAudioSession: AVAudioSession;

    init!()
    {
        self.mAudioSession = AVAudioSession.sharedInstance();

        do {
            try self.mAudioSession.setActive(false);

            try self.mAudioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions: .AllowBluetooth);
            try self.mAudioSession.setMode(AVAudioSessionModeVideoChat);
            try self.mAudioSession.setActive(true);
        }
        catch {
            return nil;
        }
    }

    func switchToDevice(device: AVAudioSessionPortDescription!) -> Bool
    {
        var ret = false;

        if (device != nil) {
            do {
                try self.mAudioSession.setPreferredInput(device);

                ret = true;
            }
            catch {
                self.logSwitch(device, error: error);
            }
        }

        return ret;
    }
}

我想了解为什么我的应用不是只在某些蓝牙设备上正常工作。这些相同的设备在我的Cel上的其他应用程序上正常工作。

I'd like to understand why my App is not working fine on just SOME Bluetooth devices. These same devices work properly on the other Apps on my Cel.

我做了另一个测试:我为MPVolumeView更改了所有这些,并且发生了完全相同的问题,所以问题似乎出现在音频播放器上。

I did another test: I changed all of this for MPVolumeView, and exactly the same issue occurred, so the problem seems to be on audio player.

有人可以给我一个建议来解决这个问题吗?

Could anybody give me a suggestion to fix this ?

Thx。

推荐答案

Jorg,
虽然这可能不是最好的答案,但我已经能够克服奇怪的蓝牙问题。我的问题似乎与你的问题类似,因为我也在使用:

Jorg, While this might not be the best answer I have been able to overcome the weird Bluetooth issues. My problem seems to be similar to yours as I too was using:

AVAudioSessionCategoryPlayAndRecord

这对我的某些蓝牙设备造成了问题(除了一些设备外)。

This was causing issues for me on some Bluetooth devices (not all but some).

我最后做的是将类别设置为:

What I wound up doing was setting the Category to:

AVAudioSessionCategoryPlayback

然后,当我需要记录时,我会将类别转换为:

Then when ever I needed to record I would switch the Category over to:

AVAudioSessionCategoryRecord

完成录制后返回播放。

这是目前唯一可以通过切换不同输出(扬声器,耳机,蓝牙)获得一致结果的方法。

This was the only way at this time I could get a consistent result from switching between the different outputs (Speaker, Headphones, Bluetooth).

希望有所帮助。猜测这是AVAudioSessionCategoryPlayAndRecord中的一个错误

Hope that helps some. Guessing this is a bug in the "AVAudioSessionCategoryPlayAndRecord"

这篇关于AVAudioSession:某些蓝牙设备在我的应用程序上无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆