Search code examples
linuxsystemdcron-taskmplayer

How to play first n seconds of a mp3 track with systemd?


Here's my try:

[Unit]
Description=play the a team song

[Service]
ExecStart=/usr/bin/mpg123 /home/pi/Music/the_a_team.mp3
RuntimeMaxSec=10

The song plays 21 seconds and then stops. I don't get it. I also didn't find another solution like telling mpg123 to play just the first n seconds. Please help me. Any solution is fine.


Solution

  • Try this:

    [Unit]
    Description=play the a team song
    
    [Service]
    ExecStart=/usr/bin/ffplay /home/pi/Music/the_a_team.mp3 -t 10 -autoexit -nodisp
    

    Note that ffplay is part of the ffmpeg package.