2024年11月24日星期日 下午9:26:47

bluez5 bluetooth speaker vlc pulseaudio home assisant on Raspberry Pi 3B

2 年 前
#3753 引用
Raspberry Pi 3B bluez5 bluetooth speaker vlc  pulseaudio home assisant


当前在一个项目上使用了bluez5.54 + pulseaudio 来做蓝牙音箱节点,

同时为了兼顾播放本地音乐和网络音频,安装了vlc, 在命令行搞bluetoothctl播放音频成功了。

但是,用cvlc 在命令行播放音乐出现问题:vlc播放后,退出,一会儿蓝牙的音频就死了,查看了一下是pulseaudio 挂了? 嗯?

一番瞎搞后发现cvlc启动的时候也是连接到pulseaudio 去解码的,但是pulseaudio播了vlc的音频,结束后pulseaudio 的状态变成了idle, 于是:

pulseaudio --exit-idle-time=-1

这样就行了,不会自动退出



更多功能还在摸索,比如如何用程序打开,如何禁用某个音源的音量等等。

pulseaudio非常强大,继续摸索。

https://magodo.github.io/PulseAudio/




既然,蓝牙和VLC都可以同时播放,pulseaudio 可以同时播出,

那么问题来了,我要选通一个通道,咋办?

vlc好办,可以停止, 蓝牙的话也可以停止,但是可能用户就直接2个模式疯狂切换呢,还有加上蓝牙连接的时候用户操作的不确定因素,比如终端点了停止,手机又点了继续播,那就很蛋疼。

所以还有个办法,就是禁用pulseaudio的sink 或者 source

vlc 和蓝牙 对于pulseaudio 来说, 是sink :

于是列出:

# pacmd list-sink-inputs
2 sink input(s) available.
    index: 9
        driver: <module-loopback.c>
        flags: VARIABLE_RATE START_CORKED
        state: RUNNING
        sink: 0 <alsa_output.0.stereo-fallback>
        volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        muted: no
        current latency: 99.84 ms
        requested latency: 65.73 ms
        sample spec: s16le 2ch 44151Hz
        channel map: front-left,front-right
                     Stereo
        resample method: trivial
        module: 29
        properties:
                media.role = "music"
                module-stream-restore.id = "sink-input-by-media-role:music"
                media.name = "Loopback from HUAWEI Mate 9"
                media.icon_name = "audio-card-bluetooth"
    index: 12
        driver: <protocol-native.c>
        flags: START_CORKED FIX_RATE
        state: RUNNING
        sink: 0 <alsa_output.0.stereo-fallback>
        volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        muted: no
        current latency: 1200.11 ms
        requested latency: 40.00 ms
        sample spec: float32le 2ch 48000Hz
        channel map: front-left,front-right
                     Stereo
        resample method: ffmpeg
        module: 12
        client: 48 <VLC media player (LibVLC 3.0.11)>
        properties:
                media.role = "video"
                media.name = "audio stream"
                application.name = "VLC media player (LibVLC 3.0.11)"
                native-protocol.peer = "UNIX socket client"
                native-protocol.version = "33"
                application.id = "org.VideoLAN.VLC"
                application.version = "3.0.11"
                application.icon_name = "vlc"
                application.language = "C"
                application.process.id = "823"
                application.process.user = "root"
                application.process.host = "buildroot"
                application.process.binary = "vlc"
                application.process.machine_id = "4460d06f23eb8dad2d7a7eb100001d8e"
                module-stream-restore.id = "sink-input-by-media-role:video"




单独静音某个声音通道:

pacmd set-sink-input-mute 12 1 #静音

pacmd set-sink-input-mute 12 0 #开声音

pacmd set-sink-input-mute 9 1 #静音

pacmd set-sink-input-mute 9 1 #开声音
0