5

The command:

omxplayer -o local sample.mp3

works fine - sound is good - but I have to wait for return until the music stops.

I want to put this in a backround. I run:

omxplayer -o local sample.mp3 &

It creates the new process in a background as it should but there is no sound. when I list jobs I can see:

[1]+  Stopped                 omxplayer -o local sample.mp3

There is a stopped job. When I start it by running fg music plays but not in a background. When I start the job by running bg it goes back to stopped jobs.

Any ideas?

  • Just to be that lazy guy who doesn't post a real answer: have you taken a look at mpd yet? I believe headless background music playing is what it was designed for. – Mikey A. Leonetti Jun 17 '16 at 12:25
2

There should be a man page (man omxplayer); the options are also explained here. I do not see a "background" or "damonize" (similar concept) option there.

This is probably because omxplayer was written specifically for the pi to exploit hardware acceleration for video playback (it may be less unique now in this sense than it once was); it will play audio mp3's simply because (educated guess) it needs to include that decoding/playback code anyway.

However, using the audio system on the pi does not require any special software written for it, so if all you want to do is listen to mp3's you can use anything that runs on linux. For a command-line interface that I think will background, try mpg123 (apt install mpg123); I believe this should be set up to use ALSA as the soundsystem so if you are using pulseaudio and don't hear anything, that's why (it could also be vice versa). Checking here (man mpg123), you can list the possibilities with:

mpg123 --list-modules

And use one, e.g.:

mpg123 -o alsa

It does mention being able to use a "comma separated list" there too (which probably means commas with no spaces).

Finally, if this is a big issue for you with omxplayer and you are using a GUI, it is obviously no big deal to open another terminal or an extra tab in the current one and just let it run there. They cost very little in memory as most of it is shared. The same logic applies if you aren't using a GUI; on the real console (i.e., screen and keyboard), try cycling through ctrl-alt + F1-F6. If you are using ssh or something, multiple connections are also cheap (and there is the screen option mentioned by PandaLion; see also tmux).

  • It does not have to be omxplayer and I don't want to use GUI in any way. Using mpg123 solved my problem. I used this command to run the process in background: mpg321 sample.mp3 >/dev/null 2>&1 & simple mpg321 sample.mp3 & sitll requiered from me to press enter. – Erroid Jun 11 '16 at 12:47
  • mpg seems a bit limited. As another alternative I can recommend mpc, which is a CLI client for mpd. – Blake Jul 28 '18 at 12:34
2

Here's an alternative

  1. Open up a screen session using the command screen. Install it if you have to.
  2. Run omxplayer -o local sample.mp3 from there.
  3. Press Ctrl+A then press D to send the screen to the background (i.e. Disconnect from the session). To connect, run screen -X.

It should continue playing in the background.

One caveat of this is that I'm not sure how to integrate this into a script (haven't done any research at the moment). I'm guessing it's possible. EDIT: Check Patrick Cook's comment.

  • 1
    If you want the screen to start in the background you can pass the -d -m arguments. Ex: screen -d -m one player -o local sample.mp3. To reattach the screen, you can use screen -r as well. – Patrick Cook Jun 11 '16 at 15:19
1

You can do exactly what you described by:

omxplayer --no-keys -o local sample.mp3 &

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.