简体   繁体   English

Pyglet播放器无法播放

[英]Pyglet player won't play

I'm writing an audio player in python using pyglet's Player class. 我正在使用pyglet的Player类在python中编写音频播放器。 This module is just a test of the Player and Source classes and it produces nothing. 该模块只是对Player和Source类的测试,不会产生任何结果。 No sound, no error, just one warning about vsync that probably has nothing to do with the actual problem. 没有声音,没有错误,只是关于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()

Also, src.play() does nothing too. 另外,src.play()也什么也没做。 What am I doing wrong? 我究竟做错了什么?

EDIT: I've also confirmed that the media.driver is the media.drivers.directsound module. 编辑:我也已经确认media.drivermedia.drivers.directsound模块。 I was afraid it was using silent . 我担心它正在使用silent

You have to somehow start the pyglet loop. 您必须以某种方式启动pyglet循环。 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. 像这样的东西行得通,但是如果您使用Pyglet,也请确保要绘制一些东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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