声音PulseAudio无法将卡配置文件设置为\'a2dp_sink\' 我怎样才能看到日志并找出错误?

・17 分钟阅读

问题:

我目前已经安装了ubuntu 16.04和a2dp,对全新的安装,我更愿意作为最后一个选项,当配对从蓝牙设置中删除,并且再次配对时,它会在a2dp的配置文件中被再次配对,但是,如果耳机断开,然后重新连接a2dp配置文件不再工作,(虽然上面写着a2dp ),只有在切换到HSP/HSF之后,才能运行,之后我就无法在a2dp上设置它了。

我已经尝试过了:


 pacmd set-card-profile <index> a2dp_sink



但出现以下错误:


"Failed to set card profile to 'a2dp_sink'"



我在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:



当它不存在时:


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:



所拥有的MODULE是:


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"



我已经尝试修改/etc/bluetooth/audio.conf,并且安装blueman,但是,它不起作用,我还尝试重新安装bluez和pulseaudio,但是,依旧没什么改变。

有什么方法我可以知道哪儿错了,并且可以修复它?


回答 1:

基于行"活动配置文件:

一个很容易用来改变配置文件的程序是pavucontrol ,你可以安装它 sudo apt install pavucontrol -y 然后,如果你在Kubuntu上,并且输入pavucontrol,就从命令行或Alt+F2运行pavucontrol 。

选择配置选项卡,然后尝试更改耳机的配置文件,并查看是否更新了你的耳机,蓝牙a2dp linux中似乎仍然存在一个bug,它会影响我的16.04安装。如果已经将A2DP更改为OFF,请断开蓝牙小程序中的设备,然后重新连接。然后继续将配置文件改为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



一个更复杂但自动化的方式是,循环配置文件关闭,然后回到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 



我也做了一个工作,使用一个显得有些草率粗暴的脚本来实现同样的事,但是,它要断开连接,并且重新连接蓝牙耳机。因为每次当设备被断开,并且重新连接时,它要去抓取概要文件索引。 就是上面列出的耳机的设备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:86n quit"|bluetoothctl;sleep 5; echo -e "connect 50:C9:71:97:A1:86n quit"|bluetoothctl; sleep 5; pacmd set-card-profile `pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}'` a2dp_sink



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

最终这个问题将在蓝牙软件包中修补,但是,似乎在新版本的Ubuntu以及其他版本的Linux中不断又回归出现。但希望这对你有帮助


回答 2:

我在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



然后


sudo chown gdm:gdm /var/lib/gdm3/.config/pulse/client.conf



我还加入了 /etc/pulse/default.pa


load-module module-switch-on-connect



尽管这可能不是必需的。

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


回答 3:

为了使你的系统被检测为一个A2DP接收器(例如,要通过电脑扬声器播放你的电话,请在/etc/bluetooth/audio.conf下的[General]下添加Enable=Source,Sink,Media,Socket

完成这个操作后,重新启动蓝牙守护进程,


systemctl restart bluetooth



连接耳机设备


bluetoothctl


connect <MAC>



检查你的卡并设置配置文件


pacmd list-cards


pacmd set-card-profile <index> <profile>




回答 4:

lagerismi在launchpad发布了一个脚本这里是基于的Jamie S 的回答

  • 更改脚本中变量中的设备的MAC-address!(可以使用bluetoothctl -- >设备找到),

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

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

  • 将脚本添加到KDE的启动/关闭脚本中

为了快速执行手动执行:

  • 向应用程序启动(也可以设置一个keyboad快捷方式,如"ctrl+alt+h "and/or将此起动器插入窗口栏)中添加条目,

脚本:


#!/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_macn quit"|bluetoothctl


sleep 5


echo "connect $device_macn quit"|bluetoothctl


sleep 5


pacmd set-card-profile `pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}'` a2dp_sink




回答 5:

在Xubuntu 16.04.2上
使用blueman管理器:

  • 连接- >设置配置文件
  • 重新连接- >设置配置文件a2dp
  • 现在你的耳机没问题!
  • 我的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="$1nquit"
    
    
     [ ! -z "$btMac" ] && cmd="select $btMacn$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 $macnconnect $mac" | grep -v 'NEW|DEL| quit'`"
    
    
     echo "$tmp"
    
    
    
     tmp="`btWaitConnect yes`"
    
    
     echo $tmp
    
    
     [ -z "`echo "$tmp" | grep yes`" ] && echo -e "Device $mac:ntConnected: 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:ntdisconnected: 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
    
    
    
    

回答 6:

因此,如果你使用Debian,你可以执行以下操作: 拒绝将配置文件切换到a2dp_sink : 未连接。

问题

蓝牙耳机已连接,但是,ALSA/PulseAudio无法连接设备或没有设备可以连接,因为GDM在GDM会话中需要可访问性,所以,GDM会在会话启动时捕获缓冲接收器,例如屏幕阅读器需要它。

解决方案

为了防止GDM在会话启动时捕获A2DP接收器,请编辑,/var/lib/gdm3/.config/pulse/client.conf (或者,如果它不存在的话):


autospawn = no


daemon-binary = /bin/true



之后,你必须向debian gdm用户授予对此文件的访问权限:


chown Debian-gdm:Debian-gdm /var/lib/gdm3/.config/pulse/client.conf



你还需要禁用pulseaudio启动:


rm /var/lib/gdm3/.config/systemd/user/sockets.target.wants/pulseaudio.socket



要自动连接到某些设备a2dp,请将它添加到/etc/pulse/default.pa


load-module module-switch-on-connect



重新引导。


回答 7:

我试图设置我的蓝牙,总是有这个错误。

我发现问题是Skype ,如果我正在运行Skype,我无法设置a2dp_sink配置文件。

所以,如果你遇到这个问题,看看你是否有Skype运行,并且关闭它。


回答 8:

我与OP的问题完全相同,但是,在Linux Mint 17/18上,我写了这个脚本可靠地获得蓝牙连接,并且使用。


#!/bin/bash



MAC=$1


CARD=$(echo "${MAC}" | sed -e 's/:/_/g')


CARD="bluez_card.${CARD}"



$(pactl list | grep -qi 'Active Profile: a2dp_sink')


a2dpUsed=$?



# this loops until a2dp is _actually used_ on the given MAC.


while [ ${a2dpUsed} -ne 0 ];


do


 #


 echo "Restarting bluetooth."


 rfkill unblock bluetooth


 sudo service bluetooth restart


 sudo hciconfig hci0 up



 # reconnect


 echo -e "power onnconnect ${MAC}" | bluetoothctl



 #


 echo "Waiting for headset to be connected..."


 btConnected=1



 while [ ${btConnected} -gt 0 ];


 do



 sleep .1


 $(bluetoothctl <<< "info ${MAC}" | grep -qi "Connected: yes")


 btConnected=$?


 done



 #


 echo "Bluetooth connected, waiting for profiles to register"



 cardFound=1


 while [ ${cardFound} -ne 0 ];


 do


 $(pactl list | grep -qi "${CARD}")


 cardFound=$?


 done



 #


 echo "Setting bluetooth a2dp profile"


 pactl set-card-profile ${CARD} a2dp_sink


 $(pactl list | grep -qi 'Active Profile: a2dp_sink')


 a2dpUsed=$?


done



echo "a2dp is working."




回答 9:


systemctl restart bluetooth



  • 打开声音设置(通过单击任务栏中的扬声器图标可访问),
  • 尝试将输出配置文件更改为A2DP接收器,
  • 如果无法正常工作,请将设备改为扬声器,或其他设备,然后将它切换回去。
  • 我通常会发现我可以设置输出配置文件,

讨论
Tianye profile image