• Recent
  • Tags
  • Popular
  • Home
  • Docs
  • Register
  • Login
RetroPie forum home
  • Recent
  • Tags
  • Popular
  • Home
  • Docs
  • Register
  • Login

[opendev] The Background Music Box

Scheduled Pinned Locked Moved Ideas and Development
cyperghostbgmmp3mpg123
33 Posts 6 Posters 5.1k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S
    Superman550
    last edited by 17 Feb 2019, 04:29

    am i missing a step because when i try to launch the script all i get is "error expect 5 tokens to launch menu but only 4 available"

    i am running 4.4 on a raspberry pi 3 b+

    C 1 Reply Last reply 17 Feb 2019, 06:33 Reply Quote 0
    • C
      cyperghost @Superman550
      last edited by cyperghost 17 Feb 2019, 06:33

      @Superman550 Then your array for mp3 files is empty. Place your mp3 files directly to /home/pi/BGM not in subfolders. Our can you tell me how your mp3 files are arranged? They need a mp3 file externsion as well.

      PS: If there are subfolders you can try to change line 76 -maxdepth 1, to 2 or completly remove this argument. You see sadly I got no response for this as I coded so I wasn't aware of different setups ;)

      EDIT: Tried with -maxdepth 2 and yes I can now acess subfolders within playlists. So this could be a possible solution. I do not change the code as long there are some responses.

      S 1 Reply Last reply 17 Feb 2019, 22:41 Reply Quote 0
      • S
        Superman550 @cyperghost
        last edited by 17 Feb 2019, 22:41

        @cyperghost i did have the files in the BGM folder and i only did one to test the script out and i did have the music player script installed but when i did disabled the music player from running at start up your script worked again

        1 Reply Last reply Reply Quote 0
        • K
          ketaketish
          last edited by 18 Feb 2019, 01:53

          Loving the script!
          1 question: I notice when I select a song, once that song is over mpg123 stops by default.
          How would I go about, or is it possible to modify the command so that once the selected song is over, it returns to shuffle mode on its own without the need to re-enter the script?

          Thanks for your work!

          C 1 Reply Last reply 18 Feb 2019, 16:21 Reply Quote 0
          • C
            cyperghost @ketaketish
            last edited by 18 Feb 2019, 16:21

            @ketaketish Thank you

            I notice when I select a song, once that song is over mpg123 stops by default.

            Yes that's a behaviour I'm aware of. But see my BGM tracks have a length of more then 60 min per track. If you want to continue music then you need a second call to mpg123 inside the script. But this is not good coding because the second will check every x seconds if the current session of mpg123 is still running or you can use wait command.

            I think it is not a great deal to restart the player in shuffle mode if you want to select a new track. Everything else is not clean coding imho. The best solution would be a player inside ES ;)

            K 2 Replies Last reply 18 Feb 2019, 16:41 Reply Quote 0
            • K
              ketaketish @cyperghost
              last edited by 18 Feb 2019, 16:41

              @cyperghost Thank you for your response!
              I must admit, I have not listened to your tracks... I kind of immediately added my own :S
              60min tracks would definitely be less of a nuance compared to my 2mins tracks haha.

              That explanation makes perfect sense. I am not as well-versed so I was more curious if it were possible but I do see that making a check every X seconds is a waste of resources.

              Keep up the good work! :)

              1 Reply Last reply Reply Quote 0
              • K
                ketaketish @cyperghost
                last edited by 18 Feb 2019, 16:47

                @cyperghost Just had a thought (if its a no then all good):

                Would there be a way to analyse the selected mp3 file for its duration? Then output that into say "Length", then use "wait $Length" before returning to shuffle?

                I love learning this stuff and have been doing most of it so far through these forums and "Trial and Error" and have learned all the Linux I know so far through it. So I do appreciate your explanations :)

                C 1 Reply Last reply 18 Feb 2019, 18:28 Reply Quote 0
                • C
                  cyperghost @ketaketish
                  last edited by cyperghost 18 Feb 2019, 18:28

                  @ketaketish about mp3 lenght... There are surly tools available that can analyse track length.

                  Easiest approch would be a small script like this

                  #!/bin/bash
                  while pidof mpg123 > /dev/nul; do
                       sleep 10
                  done
                  mpg123 -q -Z /path/to/mp3files/*.mp3
                  

                  Then you send this script to background alongside with the script. You add a line between 101 and 102 like
                  /path/to/script/above/shuffle.sh &

                  It's a dirty hack but will work

                  EDIT: Improved the dirty hack a bit

                  1 Reply Last reply Reply Quote 0
                  • C
                    cyperghost
                    last edited by cyperghost 9 Mar 2019, 22:53 3 Sept 2019, 21:08

                    @ketaketish Even if this is a very old topic. I've added the length of mp3 files (for current song only)
                    There is a package mp3info - it's very capable in getting info of tracks ;)

                    The whole script is improved alot.
                    Please install the tools lsof and mp3info before with sudo apt install lsof mp3info
                    The script will run without these but it will look more nice with the tools installed.

                    Default player is mpg123
                    Please change the player inside the script or install with sudo apt install mpg123
                    mpg123 is the smallest mp3 I know for Debian .... it's very relyable and small in footprint and won't hurt your system setup!

                    Changes:

                    • Code Cleanup
                    • Show length of current played song in mm:ss
                    • use realpath for path resolving
                    • use /dev/null hack to use mpg123 with Raspbian stretch (=RetroPie 4.5.1)
                    1 Reply Last reply Reply Quote 2
                    • C
                      cyperghost
                      last edited by cyperghost 9 May 2019, 17:03 4 Sept 2019, 19:19

                      It's possible to see tracklength of current selected track...

                      Ugly hack!! removed!!!

                      and add --item-help to your dialog config, then you can see tracklength of selected mp3 title ;) Maybe somebody can improve the coding .... I did it just in a swift way.

                      C 1 Reply Last reply 5 Sept 2019, 16:01 Reply Quote 0
                      • C
                        cyperghost @cyperghost
                        last edited by 5 Sept 2019, 16:01

                        So this is an updated version of the music player with additional info to selected mp3 file. See bottom line ....

                        Get it from here

                        1 Reply Last reply Reply Quote 0
                        • M
                          majikill
                          last edited by 29 May 2020, 20:09

                          i understand that this topic is old. but a different bgm player is no longer woking properly. That and im having way more fun setting it up and having bgm work the way it should. That being said its kind of a shame this project didnt go far, i aim to change that. Is is possible to set a different volume level for mpg123 than master setting of ES? to keep the music at a tollerable level i cant hear the games. id have to set the volume the moment i get out of a game and that can be a hassle. so im hoping there is a script or something i can use to remedy this

                          M 1 Reply Last reply 29 May 2020, 20:55 Reply Quote 0
                          • M
                            mitu Global Moderator @majikill
                            last edited by 29 May 2020, 20:55

                            @majikill said in [opendev] The Background Music Box:

                            That being said its kind of a shame this project didnt go far, i aim to change that. Is is possible to set a different volume level for mpg123 than master setting of ES.

                            You can, by defining a new ALSA device, with it's own volume - https://alsa.opensrc.org/How_to_use_softvol_to_control_the_master_volume.

                            Basically, you add in $HOME/.asoundrc

                            pcm.mp3 {
                                type            softvol
                                slave.pcm       "default"
                                control.name    "Softmaster"
                                control.card    0
                            }
                            

                            then you instruct the audio application to use the mp3 ALSA device. When you open alsamixer to se the volume, you'll have 2 mixer elements, one of them called "Softmaster", and you can set the volume individually.

                            C M 2 Replies Last reply 29 May 2020, 22:54 Reply Quote 0
                            • C
                              cyperghost @mitu
                              last edited by cyperghost 29 May 2020, 22:54

                              @mitu @majikill The method for volume change can be kept quite simpler. mpg123 -f switch scales volume level.

                              So please feel free to improve

                              32768 -- Volume 100%
                              29491  --Volume 90%
                              ...
                              16284 -- Volume 50%
                              ...
                              0 -- Mute
                              
                              M 1 Reply Last reply 29 May 2020, 23:16 Reply Quote 1
                              • M
                                majikill @cyperghost
                                last edited by 29 May 2020, 23:16

                                @cyperghost where would i apply these changes exactly? unless i make the changes to any instance mpg123 starts?

                                1 Reply Last reply Reply Quote 0
                                • M
                                  majikill @mitu
                                  last edited by 29 May 2020, 23:22

                                  @mitu this would go just in the /home directory?

                                  M 1 Reply Last reply 30 May 2020, 03:37 Reply Quote 0
                                  • M
                                    mitu Global Moderator @majikill
                                    last edited by 30 May 2020, 03:37

                                    @majikill You can try modifying the script that starts the BGM music and add the -f parameter as @cyperghost mentioned. The .asoundrc configuration file I was mentioning should be added in $HOME (which translates to /home/pi).

                                    M 2 Replies Last reply 30 May 2020, 04:23 Reply Quote 0
                                    • M
                                      majikill @mitu
                                      last edited by 30 May 2020, 04:23

                                      @mitu awesome. perfect guys thank you. im gonna try both and see what works best for me.

                                      1 Reply Last reply Reply Quote 0
                                      • M
                                        majikill @mitu
                                        last edited by 30 May 2020, 05:14

                                        @mitu i managed to create the .asoundrc file where it should be. but when i launch alsasound i only have a single mixer. i did put the file in /home/pi

                                        M 1 Reply Last reply 30 May 2020, 05:33 Reply Quote 0
                                        • M
                                          mitu Global Moderator @majikill
                                          last edited by 30 May 2020, 05:33

                                          @majikill Can you run

                                          speaker-test -D mp3
                                          

                                          and see if you get any errors ? Then start alsamixer and see if you have 2 mixer devices.

                                          M 2 Replies Last reply 30 May 2020, 15:53 Reply Quote 0
                                          • First post
                                            Last post

                                          Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                                          Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.

                                            This community forum collects and processes your personal information.
                                            consent.not_received