1

I'd like to play MP3 files on my Raspi 3B by using mpg123, so I added (among others) the following lines of code into my app:

    r = mpg123_init ();

    if (r != MPG123_OK) {
      ret -= r;
      cout << "Error initializing MP3 player." << endl;
    }
    else {
      sound::mp3_handle        = mpg123_new (NULL, &r);
      sound::mp3_output_handle = out123_new ();

      if (r != MPG123_OK) {
        e.assign (mpg123_strerror (sound::mp3_handle));

        ret -= r;
        err += err.length () > 1 ? "; " + e : e;
      }
      else {
        rr = out123_param_int (sound::mp3_output_handle, OUT123_VERBOSE, 2);
        r  = out123_open      (sound::mp3_output_handle, "alsa", NULL);

        if (r != OUT123_OK || rr != OUT123_OK) {
          e.assign (out123_strerror (sound::mp3_output_handle));

          ret -= r + rr;
          err += err.length () > 1 ? "; " + e : e;
        }
      }
    }

out123_open, though, always throws the following error message:

Trying output module: alsa, device: <nil>
Using default module dir: /usr/lib/arm-linux-gnueabihf/mpg123
Module dir: /usr/lib/arm-linux-gnueabihf/mpg123
Module path: /usr/lib/arm-linux-gnueabihf/mpg123/output_alsa.so
[src/libout123/libout123.c:451] error: Found no driver out of [alsa] working with device <default>.

The default device is a JustBoom DAC HAT named plughw:0,0. When using mpg123 on the command line (by using the device name explicitly, or resorting to the default device), everything works fine, but when using the mpg123 library functions in client code, I always get such an error, no matter whether I set the device and driver names to NULL (which means trying out the drivers out123 knows and using the default device). I don't really execute mpg123 by using fork ()!

What's the problem here? Thank you for your help.

UPDATE: After switching to the recent mpg123 version from GitHub & setting verbosity to 3, I get the follwoing messages when issuing out123_open:

Trying output module: alsa, device: plughw:0,0
Module dir search relative to: /usr/bin
Looking for module dir: /usr/bin/../lib/mpg123
Module dir: /usr/bin/../lib/mpg123
Module path: /usr/bin/../lib/mpg123/output_alsa.so
Note: alsa is the last output option... showing you any error messages now.
[src/libout123/modules/alsa.c:173] debug: open_alsa with (nil)
[src/libout123/modules/alsa.c:181] error: cannot open device plughw:0,0
[src/libout123/libout123.c:451] error: Found no driver out of [alsa] working with device plughw:0,0.

Why is open_alsa conducted with a nil argument? It's taken from the userptr field of the output handle.

0

OK, I've managed to solve the problem myself: In fact, I had prepared the sound output beforehand by using the ALSA audio API functions described in this tutorial, unfortunately including a call to the snd_pcm_open () function, which engaged the sound output device. After studying the sourcecode of out123, I found out that out123 already opens the sound device when issuing the out123_open () function – by using snd_pcm_open (), of course. However, I've still gotta find out how to make the necessary settings to ALSA when working with out123.

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.