我正在尝试在 EC2/Ubuntu 20.04 实例上运行无头浏览器,然后将生成的音频流输出到默认的 Pulseaudio 接收器(然后由 DarkIce/Icecast 拾取)。我只想运行一个网页(我的,托管在不同的服务器上,需要 jQuery 和 Howler.js),并且生成的浏览器/流必须保持 24/7 开放。
我已经设法在实例上获得一个音频文件以播放到 Icecast(使用 ogg123),所以 ogg123>Pulseaudio>Darkice>Icecast2 有效。我创建了一个默认接收器,如下所示
pactl load-module module-null-sink sink_name=radio
pacmd update-sink-proplist radio device.description=radio
pacmd set-default-sink radio
并通过创建 ~/.asoundrc 使 Pulseaudio 成为默认驱动程序以包含
pcm.default pulse
ctl.default pulse
我不确定让浏览器正常运行的正确方法是什么。我试过(google-chome和chromium)直接指向一个音频文件和一个带有js播放音频的页面(目的是最终在屏幕上运行它),两者似乎都找到了内容,都没有方法播放任何音频。例如,
google-chrome-stable --headless --disable-gpu --autoplay-policy=no-user-gesture-required --user-data-dir=/home/ubuntu/chromeUser --disable-accelerated-video-decode --disable-software-rasterizer --enable-logging=stderr --v=1 https://domain.name/stream.html
生成以下
[0608/102421.257217:INFO:cpu_info.cc(53)] Available number of cores: 1
[0608/102421.258656:INFO:cpu_info.cc(53)] Available number of cores: 1
[0608/102421.258861:VERBOSE1:zygote_main_linux.cc(217)] ZygoteMain: initializing 0 fork delegates
[0608/102421.259318:VERBOSE1:zygote_main_linux.cc(217)] ZygoteMain: initializing 0 fork delegates
[0608/102421.271947:VERBOSE1:webrtc_internals.cc(118)] Could not get the download directory.
[0608/102421.280120:VERBOSE1:breakpad_linux.cc(2071)] Non Browser crash dumping enabled for: gpu-process
[0608/102421.283276:ERROR:gpu_init.cc(440)] Passthrough is not supported, GL is disabled
[0608/102421.286107:VERBOSE1:breakpad_linux.cc(2071)] Non Browser crash dumping enabled for: renderer
[0608/102421.288099:VERBOSE1:sandbox_linux.cc(69)] Activated seccomp-bpf sandbox for process type: gpu-process.
[0608/102421.293815:VERBOSE1:sandbox_linux.cc(69)] Activated seccomp-bpf sandbox for process type: renderer.
[0608/102421.303930:VERBOSE1:device_data_manager_x11.cc(216)] X Input extension not available
[0608/102421.356750:VERBOSE1:configured_proxy_resolution_service.cc(852)] PAC support disabled because there is no system implementation
[0608/102421.357514:VERBOSE1:configured_proxy_resolution_service.cc(852)] PAC support disabled because there is no system implementation
[0608/102421.359494:VERBOSE1:network_delegate.cc(32)] NetworkDelegate::NotifyBeforeURLRequest: https://domain.name/stream.html
[0608/102421.411474:VERBOSE1:document.cc(3974)] Document::DispatchUnloadEvents() URL = <null>
[0608/102421.411727:VERBOSE1:document.cc(4054)] Actually dispatching an UnloadEvent: URL = <null>
[0608/102421.421675:VERBOSE1:network_delegate.cc(32)] NetworkDelegate::NotifyBeforeURLRequest: /path/to/jquery.min.js
[0608/102421.424968:VERBOSE1:network_delegate.cc(32)] NetworkDelegate::NotifyBeforeURLRequest: /path/to/jquery-ui.min.js
[0608/102421.429480:VERBOSE1:network_delegate.cc(32)] NetworkDelegate::NotifyBeforeURLRequest: /path/to/howler.min.js
这是让它工作的正确方法(如果是这样,为什么不呢?),还是我应该使用 Selenium/Puppeteer/其他东西?
谢谢,克里斯
[旁白:我尝试了很多方法来尝试删除“不支持直通,GL 是 swiftshader”错误,但没有成功,尽管它似乎不会阻止浏览器访问页面]
我已经设法通过运行 Puppeteer 来完成这项工作,而不是试图从命令行与 Chromium 争吵。我已经使用这个答案(希望)通过以下参数保持 Puppeteer 保持打开状态,以使音频自动启动。
在 PulseAudio 中设置默认接收器并添加 ~/.ascoundrc(如上)后,一切正常(接收器音频由 DarkIce > IceCast > 广播拾取)。我可能会使用pm2来监督 Puppeteer,但目前它是一个可行的解决方案。