Music lagging during game

92 views
Skip to first unread message

pyglet

unread,
May 27, 2011, 1:33:31 PM5/27/11
to pyglet-users
Hello,

I am new using pyglet with python processing. I am making a quiz game
project for school and am almost done but there is a a problem with
the background music in my quiz game program. Although there are no
problems with my .wav file when you play it through windows media
player, it lags and gives some static when I run python. Another issue
is that when I change the pages of th quiz the program lags, and the
music lags with it, sounding like a scratched record.

This is a sample of the program that I am using. [Full code here:
http://pastie.org/1981722]

player = media.Player()
source = media.load("Music/MySecret.wav")
player.queue(source)
player.play()

I also have tried using this code:

from pyglet.media import StaticSource, load
BackgroundMusic3 = StaticSource (load("Music/MySecret2.mp3",
streaming=False))

def setup():

size(1300,580)
BackgroundMusic3.play()

Any help is greatly appreciated. Thank you in advance,

Lantsford Lawliet

Peter Enerccio

unread,
May 28, 2011, 6:27:29 AM5/28/11
to pyglet...@googlegroups.com
I have no idea why it should lag, but it did lag on me as well, so I
decided to use pymedia for the music playback. You can make your own
threaded class for music playback and use it instead of the normal
media.Play()

2011/5/27 pyglet <l.lati...@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups "pyglet-users" group.
> To post to this group, send email to pyglet...@googlegroups.com.
> To unsubscribe from this group, send email to pyglet-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en.
>
>

Peter Enerccio

unread,
May 28, 2011, 9:15:25 AM5/28/11
to pyglet...@googlegroups.com
Forgot the example player I made:
http://paste.pound-python.org/show/7327/

Usage:
# we grab the source to StringIO (doesnt have to be, but its better
not to read from the hdd all the time)
media = open("foo.mp3", "rb")
source = StringIO.StringIO(media.read())
media.close()

# we make player instance
player = Player()

# We pass the data to the player and run the thread (it will not start
the playback until we run .play() method though
player.add_data(source, "foo.mp3")
player.run()

# we set up the exception callback if we need the info that playback failed
player.set_exception_callback(my_exception_catching_func)

# we start the playback
player.play()

# we change the volume to 50%
player.volume = 0.5

# we pause player
player.pause()

# we resume player
player.resume()
or
player.play()

# we loop player
player.change_repeat(True)
or
player.repeat = True

# we end the playback
player.stop()


I use it in my cocos2d + pyglet based game and it does not lag at all,
unlike the original player.
Hope it helps!

2011/5/28 Peter Enerccio <ener...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages