1

I'm writing an audio player in python using pyglet's Player class. This module is just a test of the Player and Source classes and it produces nothing. No sound, no error, just one warning about vsync that probably has nothing to do with the actual problem.

import pyglet.media as media
def main():
  fname='D:\\Music\\JRR Tolkien\\LotR Part I The Fellowship of the Ring\\01-- 0001 Credits.mp3'
  src=media.load(fname)
  player=media.Player()
  player.queue(src)
  player.volume=1.0
  player.play()
if __name__=="__main__":
  main()

Also, src.play() does nothing too. What am I doing wrong?

EDIT: I've also confirmed that the media.driver is the media.drivers.directsound module. I was afraid it was using silent.

colossus16
  • 135
  • 1
  • 6

1 Answers1

2

You have to somehow start the pyglet loop. Besides drawing the screen, calls the event handlers and plays the sounds.

import pyglet
import pyglet.media as media
def main():
    fname='D:\\test.mp3'
    src=media.load(fname)
    player=media.Player()
    player.queue(src)
    player.volume=1.0
    player.play()
    try:
        pyglet.app.run()
    except KeyboardInterrupt:
        player.next()

if __name__=="__main__":
    main()

Something like that works, but if you use Pyglet also sure you'll want to draw something.

Txema
  • 849
  • 5
  • 15
  • OK, I tried that but now it freezes right after `player.play()` not reaching print statements I placed after `pyglet.app.run()` and `player.next()` still without error. – colossus16 Jun 13 '13 at 14:20
  • I'm now running `pyglet.app.run` in a `Thread` and printing `player.time` continuously but that shows zeroes so it must not be playing at all. – colossus16 Jun 13 '13 at 14:30
  • The example works for me. Try to create a pyglet Window, and your print statements will be reached when you close the window. Do you have AVBin installed? Does it work with a wav file? – Txema Jun 22 '13 at 18:28