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?

Seamus
  • 23,558
  • 5
  • 42
  • 83
Marcin Majchrzak
  • 159
  • 1
  • 1
  • 3

4 Answers4

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).

goldilocks
  • 60,325
  • 17
  • 117
  • 234
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.

Aloha
  • 7,176
  • 1
  • 29
  • 52
1

You can do exactly what you described by:

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

Chupo_cro
  • 111
  • 2
0

This worked very well for me. All you have to do is change C:\Windows\Media\Windows Critical Stop.wav to whatever your file name is.

@echo off

title ERROR

::"setting up" error sound - creating vbs file to make sound set "file=C:\Windows\Media\Windows Critical Stop.wav" ( echo Set Sound = CreateObject("WMPlayer.OCX.7"^) echo Sound.URL = "%file%" echo Sound.Controls.play echo do while Sound.currentmedia.duration = 0 echo wscript.sleep 100 echo loop echo wscript.sleep (int(Sound.currentmedia.duration^)+1^)*1000) >sound.vbs

::playing sound start /min sound.vbs

::wait 1 second for vbs to let go of file ping n- 1 127.0.0.1>nul

::delete vbs file del sound.vbs