pygame.mixer.music not playing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marian Aldenhövel

    #1

    pygame.mixer.music not playing

    Hi,

    I am trying to make pygame play music on windows. This simple program:

    import pygame,time
    pygame.init()
    print "Mixer settings", pygame.mixer.ge t_init()
    print "Mixer channels", pygame.mixer.ge t_num_channels( )
    pygame.mixer.mu sic.set_volume( 1.0)
    pygame.mixer.mu sic.load('file1 .mp3)
    print "Play"
    pygame.mixer.mu sic.play()

    while pygame.mixer.mu sic.get_busy():
    print "Playing", pygame.mixer.mu sic.get_pos()
    time.sleep(1)

    print "Done"

    seems to work. It runs the loop and prints values that look like ms into the
    file. After a reasonable time corresponding to the length of "file1.mp3" the
    loop is exited and the program ends.

    The same thing happens for .mp3 files, .ogg files and .wav files.

    Fine. The only problem is that there is no sound :-).

    What am I doing wrong? pyGame example games do play sound, but I have not
    found an example that uses music.

    My ultimate goal is to build a MP3 jukebox that runs on Windows and Linux. I
    have chosen pyGame as I am making a graphical Frontend using OpenGL. I have
    also tried to look at pymad (which I could not get to work on Windows, no
    C-Compiler on this machine and I could not find binaries) and audiere (no
    skipping, at least in the python binding. A feature I would like to have.)

    Ciao, MM
    --
    Marian Aldenhövel, Rosenhain 23, 53123 Bonn. +49 228 624013.

    "Wir brauchen keine Opposition, wir sind bereits Demokraten."
  • M.E.Farmer

    #2
    Re: pygame.mixer.mu sic not playing

    Marian Aldenhövel wrote:[color=blue]
    > Hi,
    >
    > I am trying to make pygame play music on windows. This simple[/color]
    program:[color=blue]
    >
    > import pygame,time
    > pygame.init()
    > print "Mixer settings", pygame.mixer.ge t_init()
    > print "Mixer channels", pygame.mixer.ge t_num_channels( )
    > pygame.mixer.mu sic.set_volume( 1.0)
    > pygame.mixer.mu sic.load('file1 .mp3)
    > print "Play"
    > pygame.mixer.mu sic.play()
    >
    > while pygame.mixer.mu sic.get_busy():
    > print "Playing", pygame.mixer.mu sic.get_pos()
    > time.sleep(1)
    >
    > print "Done"
    >
    > seems to work. It runs the loop and prints values that look like ms[/color]
    into the[color=blue]
    > file. After a reasonable time corresponding to the length of[/color]
    "file1.mp3" the[color=blue]
    > loop is exited and the program ends.
    >
    > The same thing happens for .mp3 files, .ogg files and .wav files.
    >
    > Fine. The only problem is that there is no sound :-).
    >
    > What am I doing wrong? pyGame example games do play sound, but I have[/color]
    not[color=blue]
    > found an example that uses music.
    >
    > My ultimate goal is to build a MP3 jukebox that runs on Windows and[/color]
    Linux. I[color=blue]
    > have chosen pyGame as I am making a graphical Frontend using OpenGL.[/color]
    I have[color=blue]
    > also tried to look at pymad (which I could not get to work on[/color]
    Windows, no[color=blue]
    > C-Compiler on this machine and I could not find binaries) and audiere[/color]
    (no[color=blue]
    > skipping, at least in the python binding. A feature I would like to[/color]
    have.)[color=blue]
    >
    > Ciao, MM
    > --
    > Marian Aldenhövel, Rosenhain 23, 53123 Bonn. +49 228 624013.
    > http://www.marian-aldenhoevel.de
    > "Wir brauchen keine Opposition, wir sind bereits Demokraten."[/color]

    Hello Marian,
    First thing out i must tell you that pygame is ok for games but the
    music quality is sometimes sketchy, you must set the bit rate to get
    good sound quality and there are many other pitfalls. Search the net.
    You are not the first to try and build a jukebox out of pygame ;)

    Py> import pygame
    Py> pygame.mixer.in it()
    Py> pygame.mixer.mu sic.load('c:/everyday.mp3')
    Py> pygame.mixer.pl ay()
    Py> pygame.mixer.mu sic.fadeout(400 0)

    You have a typo in the code you posted that may be your problem.
    M.E.Farmer

    Comment

    • Marian Aldenhövel

      #3
      Re: pygame.mixer.mu sic not playing

      Hi,
      [color=blue]
      > Search the net. You are not the first to try and build a jukebox out of pygame ;)[/color]

      I did find a few, yes.

      Currently this is a toy project as I am learning the language, so early
      success means more to me than perfect results. And, as I said, I do not really
      have an alternative.

      Maybe some way to remote control another player would be in order. Leave it
      to software that is specialized and all. But I would want something that runs
      on Windows and Linux which narrows down my options.
      [color=blue]
      > You have a typo in the code you posted that may be your problem.[/color]

      You are refering to the missing ' in the filename?

      pygame.mixer.mu sic.load('file1 .mp3)

      No, that's not the problem. I did paste working code but I then edited out the
      full absolute path that I had coded into the program and introduced the error.

      I also tried your sample but no difference. Must be something on my system
      as it does seem to play...

      Ciao, MM
      --
      Marian Aldenhövel, Rosenhain 23, 53123 Bonn. +49 228 624013.

      "Wir brauchen keine Opposition, wir sind bereits Demokraten."

      Comment

      • Greg Krohn

        #4
        Re: pygame.mixer.mu sic not playing

        Marian Aldenhövel wrote:[color=blue]
        > Hi,
        >
        > I am trying to make pygame play music on windows. This simple program:
        >
        > import pygame,time
        > pygame.init()
        > print "Mixer settings", pygame.mixer.ge t_init()
        > print "Mixer channels", pygame.mixer.ge t_num_channels( )
        > pygame.mixer.mu sic.set_volume( 1.0)
        > pygame.mixer.mu sic.load('file1 .mp3)
        > print "Play"
        > pygame.mixer.mu sic.play()
        >
        > while pygame.mixer.mu sic.get_busy():
        > print "Playing", pygame.mixer.mu sic.get_pos()
        > time.sleep(1)
        >
        > print "Done"[/color]

        I tried this exact same code (except the mp3 filename, of course) on my
        machine and it worked fine. ActivePython 2.3.4 and Pygame 1.6. Could it
        be a hardware problem?

        -greg

        Comment

        • Daniel Bickett

          #5
          Re: pygame.mixer.mu sic not playing

          Marian Aldenhövel wrote:[color=blue]
          > Maybe some way to remote control another player would be in order. Leave it
          > to software that is specialized and all. But I would want something that runs
          > on Windows and Linux which narrows down my options.[/color]

          Perhaps Zinf?



          --
          Daniel Bickett
          dbickett at gmail.com

          Comment

          • M.E.Farmer

            #6
            Re: pygame.mixer.mu sic not playing

            Hello again,
            Sorry you have had no success. I would suspect it is your system
            setup.
            Seems the code is working. I didn't think you had the typo problem,
            just mentioned it because it says somewhere in the docs that if the
            mixer has problems with file loading it would result in a proxy object
            that supported the play and stop commands.
            Please post your os name and version, Python version, Pygame version,
            etc.
            Some genius out there might know how to fix it.
            Also you can try and look for another sound package, like maybe pyFMOD
            ;)
            Home of FMOD http://www.fmod.org/
            and the Python bindings http://sourceforge.net/projects/uncassist
            the people who wrote pyFMOD (lots of stuff there)
            http://www.cs.unc.edu/~parente/tech/tr01.shtml
            Hth,
            M.E.Farmer

            Comment

            • Marian Aldenhövel

              #7
              Re: pygame.mixer.mu sic not playing

              Hi,
              [color=blue]
              > Please post your os name and version, Python version, Pygame version,[/color]

              German Windows XP Home, 2.3.4, 1.6
              [color=blue]
              > Also you can try and look for another sound package[/color]

              I will. Until I find something suitable I will just build a dummy class
              that has the commands I need, I can later interface that to whatever I
              really use. Should I ever get to that point - as I said, this is a toy
              project and they tend to die suddenly :-).

              Ciao, MM
              --
              Marian Aldenhövel, Rosenhain 23, 53123 Bonn. +49 228 624013.

              "Wir brauchen keine Opposition, wir sind bereits Demokraten."

              Comment

              • Marian Aldenhövel

                #8
                Re: pygame.mixer.mu sic not playing

                Hi,
                [color=blue]
                > Could it be a hardware problem?[/color]

                I don't think so. I can play sounds on this machine and I can also play
                this very file using Windows Media Player. I suspect it's software, but
                I do not know at which level the problem may lie.

                Ciao, MM
                --
                Marian Aldenhövel, Rosenhain 23, 53123 Bonn. +49 228 624013.

                "Wir brauchen keine Opposition, wir sind bereits Demokraten."

                Comment

                • Marian Aldenhövel

                  #9
                  Re: pygame.mixer.mu sic not playing

                  Hi,
                  [color=blue]
                  > Perhaps Zinf?[/color]

                  I could not find anything about remote-controlling it. Did not install
                  it, however.

                  Ciao, MM
                  --
                  Marian Aldenhövel, Rosenhain 23, 53123 Bonn. +49 228 624013.

                  "Wir brauchen keine Opposition, wir sind bereits Demokraten."

                  Comment

                  • M.E.Farmer

                    #10
                    Re: pygame.mixer.mu sic not playing

                    Just curious what is not suitable about FMOD ?
                    It seems to be exactly what you are looking for.
                    Cross platform, free, great sound, python bindings, no compiler needed.
                    M.E.Farmer

                    Comment

                    • Marian Aldenhövel

                      #11
                      Re: pygame.mixer.mu sic not playing

                      Hi,
                      [color=blue]
                      > Also you can try and look for another sound package, like maybe pyFMOD[/color]

                      I have looked at it. While I do not like some of the boasting on the FMOD
                      site it does seem very suitable.

                      FMOD is cross-platform but pyFMOD is available only as Win32-Setup. Does
                      that mean it cannot be made to work on Linux or is it just not packaged
                      for it? It looks like your standard DLL-Import-File as known from other
                      languages and uses ctypes (had to install that first). How hard can it be
                      to make a version that loads a shared library with the same API on Linux?

                      To make pyFMOD work with the current version of FMOD I had to fix it in a
                      few obvious places. After doing so the new version of my micro-program
                      looks like this:

                      import time
                      from pyFMOD import *

                      res = FSOUND_Init(441 00, 32, 0)
                      print "FSOUND_Ini t() =", res

                      stream = FSOUND_Stream_O pen("file1.mp3" ,0,0,0)
                      print "FSOUND_Stream_ Open() =", stream

                      res = FSOUND_Stream_P lay(FSOUND_FREE ,stream)
                      print "FSOUND_Stream_ Play() =", res

                      while True:
                      print "FSOUND_Stream_ GetTime() =", FSOUND_Stream_G etTime(stream)
                      time.sleep(1)

                      And plays fine. Now I need to read up on FMODs API to find out how to
                      eliminate the "while True;" but that should not be a problem. This would give
                      me a very rich API with full control.

                      I am having fun! Thank you all.

                      Ciao, MM
                      --
                      Marian Aldenhövel, Rosenhain 23, 53123 Bonn. +49 228 624013.

                      "Wir brauchen keine Opposition, wir sind bereits Demokraten."

                      Comment

                      • M.E.Farmer

                        #12
                        Re: pygame.mixer.mu sic not playing

                        Very cool,
                        glad you got it working.
                        Good job getting it all installed and running so fast.
                        It won't be long till you have a cool media player of your own.
                        I have not used PyFMOD yet so can't help with it ( I thought it was
                        cross platform too **sigh**, at least FMOD is)
                        Happy hacking,
                        M.E.Farmer

                        Comment

                        • Marian Aldenhövel

                          #13
                          Re: pygame.mixer.mu sic not playing

                          Hi,
                          [color=blue]
                          > Just curious what is not suitable about FMOD?[/color]

                          Nothing. See my other posting. It just took me some time...

                          Ciao, MM
                          --
                          Marian Aldenhövel, Rosenhain 23, 53123 Bonn. +49 228 624013.

                          "Wir brauchen keine Opposition, wir sind bereits Demokraten."

                          Comment

                          Working...