PulseAudio 无法将卡配置文件设置为“a2dp_sink”。如何查看日志并找出问题所在?

Jua*_*pez 48 sound pulseaudio bluetooth alsa 16.04

我目前安装了 ubuntu 16.04 和 a2dp 用于全新安装,我更愿意将其作为最后一个选项。当配对从蓝牙设置中删除并再次配对时,有时它会设法在 a2dp 配置文件上,但如果耳机断开连接然后重新连接,a2dp 配置文件不再起作用(尽管它说是在 a2dp 上),它只能工作切换到 HSP/HSF 后,我无法将其设置为 a2dp。

我试过这样做:

 pacmd set-card-profile <index> a2dp_sink
Run Code Online (Sandbox Code Playgroud)

但出现以下错误:

"Failed to set card profile to 'a2dp_sink'"
Run Code Online (Sandbox Code Playgroud)

我对 Linux 缺乏经验,所以我不知道如何获取日志或在其中查找什么,但是我从 pacmd list-cards 中得到了这个:

当它工作时:

name: <bluez_card.50_C9_71_97_A1_86>
driver: <module-bluez5-device.c>
owner module: 27
properties:
    device.description = "Jabra REVO a4.0.0"
    device.string = "50:C9:71:97:A1:86"
    device.api = "bluez"
    device.class = "sound"
    device.bus = "bluetooth"
    device.form_factor = "headset"
    bluez.path = "/org/bluez/hci0/dev_50_C9_71_97_A1_86"
    bluez.class = "0x240404"
    bluez.alias = "Jabra REVO a4.0.0"
    device.icon_name = "audio-headset-bluetooth"
    device.intended_roles = "phone"
profiles:
    headset_head_unit: Headset Head Unit (HSP/HFP) (priority 20, available: unknown)
    a2dp_sink: High Fidelity Playback (A2DP Sink) (priority 10, available: unknown)
    off: Off (priority 0, available: yes)
active profile: <a2dp_sink>
sinks:
    bluez_sink.50_C9_71_97_A1_86/#6: Jabra REVO a4.0.0
sources:
    bluez_sink.50_C9_71_97_A1_86.monitor/#10: Monitor of Jabra REVO a4.0.0
ports:
    headset-output: Headset (priority 0, latency offset 0 usec, available: unknown)
        properties:

    headset-input: Headset (priority 0, latency offset 0 usec, available: unknown)
        properties:
Run Code Online (Sandbox Code Playgroud)

当它没有时:

name: <bluez_card.50_C9_71_97_A1_86>
driver: <module-bluez5-device.c>
owner module: 25
properties:
    device.description = "Jabra REVO a4.0.0"
    device.string = "50:C9:71:97:A1:86"
    device.api = "bluez"
    device.class = "sound"
    device.bus = "bluetooth"
    device.form_factor = "headset"
    bluez.path = "/org/bluez/hci0/dev_50_C9_71_97_A1_86"
    bluez.class = "0x240404"
    bluez.alias = "Jabra REVO a4.0.0"
    device.icon_name = "audio-headset-bluetooth"
    device.intended_roles = "phone"
profiles:
    headset_head_unit: Headset Head Unit (HSP/HFP) (priority 20, available: unknown)
    a2dp_sink: High Fidelity Playback (A2DP Sink) (priority 10, available: yes)
    off: Off (priority 0, available: yes)
active profile: <off>
ports:
    headset-output: Headset (priority 0, latency offset 0 usec, available: yes)
        properties:

    headset-input: Headset (priority 0, latency offset 0 usec, available: unknown)
        properties:
Run Code Online (Sandbox Code Playgroud)

拥有的模块是:

name: <module-bluez5-device>
argument: <path=/org/bluez/hci0/dev_50_C9_71_97_A1_86>
used: 0
load once: no
properties:
    module.author = "João Paulo Rechi Vita"
    module.description = "BlueZ 5 Bluetooth audio sink and source"
    module.version = "8.0"
Run Code Online (Sandbox Code Playgroud)

我已经尝试修改 /etc/bluetooth/audio.conf 并安装 blueman 但它没有用。我也尝试重新安装 bluez 和 pulseaudio 但没有任何改变。

有什么办法可以让我知道出了什么问题并修复它?

小智 38

为了让您的系统被检测为A2DP接收器(例如,通过计算机扬声器从您的手机播放音乐),加Enable=Source,Sink,Media,Socket[General]/etc/bluetooth/audio.conf

执行此操作后,重新启动蓝牙守护进程

systemctl restart bluetooth
Run Code Online (Sandbox Code Playgroud)

连接您的耳机设备

bluetoothctl
connect <MAC>
Run Code Online (Sandbox Code Playgroud)

检查您的卡并设置个人资料

pactl list cards short
pacmd set-card-profile <index> <profile>
Run Code Online (Sandbox Code Playgroud)

  • 在 ARch / Manjaro 上工作!然而,对于最新版本,该文件现在位于`/etc/bluetooth/main.conf` (7认同)
  • 使用 ubuntu 16.04 /etc/bluetooth/audio.conf 不存在,我应该在哪里写这一行? (2认同)

Jam*_* S. 31

基于“活动配置文件:<关闭>”这一行,声音配置文件没有激活。

一种易于用于更改配置文件的程序是 pavucontrol。您可以使用sudo apt install pavucontrol -y. 如果您在 Kubuntu 上并输入 pavucontrol,则从命令行或 Alt+F2 运行 pavucontrol。

选择配置选项卡,然后尝试更改耳机的配置文件,看看是否为您更新。linux 中似乎仍然存在蓝牙 a2dp 的错误,它影响了我的两个 16.04 安装。如果它已经说 A2DP 将其更改为关闭,请在蓝牙小程序中断开设备,然后重新连接。然后最后继续将配置文件更改回 A2DP,它应该可以工作。

您也可以在命令行上尝试以下操作,它应该会为您完成大部分内容。将数字 2 替换为以下两个 pacmd 命令的当前索引号。

pacmd set-card-profile 2 off
bluetoothctl
disconnect 50:C9:71:97:A1:86
connect 50:C9:71:97:A1:86
pacmd set-card-profile 2 a2dp_sink
Run Code Online (Sandbox Code Playgroud)

对于一种更复杂但自动化的方法,可以将配置文件循环关闭然后返回到 a2dp 但不断开蓝牙设备并进行连接

index=`pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}'`;pacmd set-card-profile $index off; pacmd set-card-profile $index a2dp_sink 
Run Code Online (Sandbox Code Playgroud)

我还要制作一个工作但草率的脚本来做同样的事情,但也要断开并重新连接蓝牙耳机。它获取配置文件索引,因为每次设备断开连接和重新连接时索引都会更改。这是使用上面列出的耳机的设备 ID 硬编码的

pacmd set-card-profile `pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}'` off; sleep 2 ; echo -e "disconnect 50:C9:71:97:A1:86\n quit"|bluetoothctl;sleep 5; echo -e "connect 50:C9:71:97:A1:86\n quit"|bluetoothctl; sleep 5; pacmd set-card-profile `pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}'` a2dp_sink
Run Code Online (Sandbox Code Playgroud)

在测试期间,我的睡眠时间为 5 秒而不是 3 秒,因为设备还没有准备好更改音频配置文件。您的结果可能会有几秒 +/- 5 秒的差异。编辑关于潜在的陷阱。我确实发现偶尔需要在较大的脚本工作之前运行两次。我不确定增加睡眠时间是否有帮助,因为我还没有测试过。但是我已经在两台带有相同品牌 BT 耳机的机器上使用了它,并且它正在做它应该做的事情来自动化过程以使声音在耳机上工作。

最终该问题将在蓝牙包中修复,但似乎在新版本的 Ubuntu 以及其他版本的 Linux 中不断出现。但无论如何希望对你有帮助


小智 14

我在 Ubuntu 16.04.1 LTS 上遇到了这个问题,应用https://wiki.debian.org/BluetoothUser/a2dp 中的 GDM 工作解决了这个问题。

具体来说,创建/编辑/var/lib/gdm3/.config/pulse/client.conf以阅读:

autospawn = no
daemon-binary = /bin/true
Run Code Online (Sandbox Code Playgroud)

然后

sudo chown gdm:gdm /var/lib/gdm3/.config/pulse/client.conf
Run Code Online (Sandbox Code Playgroud)

我还添加到 /etc/pulse/default.pa

load-module module-switch-on-connect
Run Code Online (Sandbox Code Playgroud)

虽然这可能不是绝对必要的。

重新启动后,我通过蓝牙管理器连接能够成功地将音频配置文件切换到a2dp_sink.


小智 5

lagerismi根据Jamie S 的回答在启动板上发布了一个脚本

  • 更改脚本内变量中的设备 MAC 地址!(可以通过bluetoothctl--> 设备找到)

  • 使脚本可执行 chmod a-x bluetooth_headphone_reactivation.sh

启动时自动执行(仅当耳机已打开时才有效):

  • 将脚本添加到 KDE 控制面板中的启动/关闭脚本

对于快速手动执行:

  • 向应用程序启动器添加一个条目(您还可以设置键盘快捷键,如“CTRL+ALT+H”和/或将此启动器固定到窗口栏)

剧本:

#!/bin/sh
device_mac='<your-devices-mac-address-here>'
pacmd set-card-profile `pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}'` off
sleep 2 
echo "disconnect $device_mac\n quit"|bluetoothctl
sleep 5
echo "connect $device_mac\n quit"|bluetoothctl
sleep 5
pacmd set-card-profile `pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}'` a2dp_sink
Run Code Online (Sandbox Code Playgroud)


小智 5

在 Xubuntu 16.04.2 上
使用 blueman-manager:

  1. 连接 -> 设置配置文件关闭
  2. 重新连接 -> 设置配置文件 a2dp
  3. 现在你的耳机没问题了!

我的 JBL bash 脚本

#!/bin/bash
#headset mac
mac="00:1D:DF:67:0A:29"
profile="a2dp"
# Special Bluetooth controller, default is empty
btMac=""
#connect|disconnect wait time
waitTime=5

macId="${mac//:/_}"
deviceId="bluez_card.$macId"

declare -A profiles
profiles['a2dp']='a2dp_sink'
profiles['hsp']='headset_head_unit'
profiles['off']='off'

function btCmd() {
    cmd="$1\nquit"
    [ ! -z "$btMac" ] && cmd="select $btMac\n$cmd"
    echo -e "$cmd" | bluetoothctl
}
function setProfile() {
    cmd="pactl set-card-profile $deviceId ${profiles[$1]}"
    echo $cmd
    $cmd
}
function btWaitConnect() {
    conState=$1
    for ((i=1;i<=$waitTime;++i)); do
        tmp="`btCmd "info $mac"|grep 'Connected: '`"
        [ ! -z "`echo "$tmp"|grep $conState`" ] && echo "$tmp" && return 0
        sleep 1s
    done
    echo "$tmp"
    return 1
}
function btConnect() {
    tmp="`btCmd "trust $mac\nconnect $mac" | grep -v 'NEW\|DEL\| quit'`"
    echo "$tmp"

    tmp="`btWaitConnect yes`"
    echo $tmp
    [ -z "`echo "$tmp" | grep yes`" ] && echo -e "Device $mac:\n\tConnected: fail." && return 1
    sleep 2s
    return 0
}
function btDisConnect() {
    tmp="`btCmd "disconnect $mac" | grep -v 'NEW\|DEL\| quit'`"
    echo "$tmp"

    tmp="`btWaitConnect no`"
    echo $tmp
    [ -z "`echo "$tmp" | grep no`" ] && echo -e "Device $mac:\n\tdisconnected: fail." && return 1
    sleep 1s
    return 0    
}


# controller
echo ""
btCtls="`btCmd list | grep '^Controller' | grep " $btMac"`"
echo -e "controller:\n$btCtls"
[ -z "$btCtls" -o ! -z "`echo "$btCtls" | grep "not available"`" ] && exit 1


# connect -> set off
echo ""
tmp="`btCmd paired-devices | grep '^Device' | grep " $mac"`"
echo -e "paired-devices:\n$tmp"
[ `echo "$tmp" | wc -l` != 1 ] && echo "Please pair the Bluetooth headset first: $mac" && exit 1
btConnect || exit $?
setProfile off

# reconnect -> set profile
btDisConnect || exit $?
btConnect || exit $?
setProfile $profile
Run Code Online (Sandbox Code Playgroud)