1

我正在使用 pyglet 的 Player 类在 python 中编写音频播放器。这个模块只是对 Player 和 Source 类的测试,它什么也没产生。没有声音,没有错误,只有一个关于 vsync 的警告,可能与实际问题无关。

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()

此外, src.play() 也不做任何事情。我究竟做错了什么?

编辑:我也确认media.drivermedia.drivers.directsound模块。我担心它正在使用silent.

4

1 回答 1

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.

于 2013-06-13T10:07:59.123 回答