Hi,
I am new to BalenaOS and need help with playing audio from a container.
I am trying to play an mp3 file from a python program running in my container, pushed to BalenaOS 2.48.0+rev1 and supervisor 10.8.0 running on a BalenaFin(cm3) in local mode.
And I am getting an error ‘pygame.error: No available audio device’, I am using pypi package pygame to play my audio file. Before moving to BalenaOS, I was able to run the same program play audio files with Raspbian-buster-light installed on BalenFin(cm3). Not sure what I am missing!!!
[Logs] [5/19/2020, 1:24:06 PM] [mosquitto] 1589865846: Socket error on client auto-F03E4FCE-B00D-9FDD-90B6-706FB2542667, disconnecting.
[Logs] [5/19/2020, 1:24:21 PM] Service exited ‘mercury-alerts-service sha256:9f2ef7dab94acf7927bc111db04e6a6bb67f18e2199cb2766bc4c63630ad38f1’
[Logs] [5/19/2020, 1:24:22 PM] Restarting service ‘mercury-alerts-service sha256:9f2ef7dab94acf7927bc111db04e6a6bb67f18e2199cb2766bc4c63630ad38f1’
[Logs] [5/19/2020, 1:24:06 PM] [mercury-alerts-service] setting log level %i 20
[Logs] [5/19/2020, 1:24:06 PM] [mercury-alerts-service] Traceback (most recent call last):
[Logs] [5/19/2020, 1:24:06 PM] [mercury-alerts-service] File “./service.py”, line 5, in
[Logs] [5/19/2020, 1:24:06 PM] [mercury-alerts-service] AlertsService().run()
[Logs] [5/19/2020, 1:24:06 PM] [mercury-alerts-service] File “/mercury/services/alerts_service.py”, line 42, in init
[Logs] [5/19/2020, 1:24:06 PM] [mercury-alerts-service] self.audio_player = AudioPlayer()
[Logs] [5/19/2020, 1:24:06 PM] [mercury-alerts-service] File “/mercury/services/alerts_service.py”, line 212, in init
[Logs] [5/19/2020, 1:24:06 PM] [mercury-alerts-service] pygame.mixer.init()
[Logs] [5/19/2020, 1:24:06 PM] [mercury-alerts-service] pygame.error: No available audio device
docker-compose.yml is
version: '2.1'
volumes:
alerts-service:
services:
mercury-alerts-service:
build: ./alerts-service/
network_mode: "host"
volumes:
- alerts-service:/app
devices:
- "/dev/snd:/dev/snd"
mosquitto:
image: "eclipse-mosquitto"
ports:
- "1883:1883"
network_mode: "host"
I have asound.conf with following setting and copied to /etc/
pcm.!default {
type hw
card 1
}
ctl.!default {
type hw
card 1
}
Dockerfile is
FROM balenalib/raspberrypi3-python:3.7
WORKDIR ./
RUN mkdir ./app \
RUN mkdir ./app/logs \
&& mkdir ./app/config \
&& mkdir ./app/media
RUN install_packages python-dev gcc alsa-utils libsdl-image1.2-dev \
libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev \
libsmpeg-dev python-numpy subversion libportmidi-dev \
ffmpeg libswscale-dev libavformat-dev libavcodec-dev \
libfreetype6-dev
COPY asound.conf /etc/asound.conf
COPY requirements.txt ./
COPY .env ./app
COPY ./config ./app/config
COPY ./media ./app/media
COPY ./mercury ./mercury
RUN pip install -r requirements.txt
ENV PYTHONPATH "${PYTHONPATH}:./mercury"
COPY . .
CMD [ "python", "./service.py" ]