简体   繁体   中英

Pyglet player won't play

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM