gpt4 book ai didi

linux - 在 Ubuntu 上使用 python 2.7 和 pyglet 的 Mp3 播放器

转载 作者:太空宇宙 更新时间:2023-11-04 12:30:53 24 4
gpt4 key购买 nike

我正在尝试使用 pyglet 在 python 中制作一个 mp3 播放器,我想显示正在播放的当前歌曲名称。我尝试使用 SourceInfo 类,但我不知道它是如何工作的 pyglet.media.SourceInfo.title 不显示任何内容。请你帮助我好吗?谢谢

最佳答案

首先,确保安装了 AvBin!
否则,除了 wav 文件之外,您将无法播放其他内容。

请记住,这只是您所需内容的粗略模型。
建立在它的基础上,废弃它..但这是一个开始。

import pyglet
pyglet.options['audio'] = ('pulse', 'alsa')

window = pyglet.window.Window(width=800, height=600)

player=pyglet.media.Player()
# == Queue more tracks,
# the label will update automatically
player.queue( pyglet.media.load('./Downloads/music/Pendulum - Hold Your Color.mp3', streaming=True) )
player.volume=0.3

# window is the variable 'window' from earlier.
@window.event
def on_draw():
window.clear()

if player.playing:
label = pyglet.text.Label('{artist} - {song}'.format(**{'artist' : player.source.info.author.decode('UTF-8'),
'song' : player.source.info.title.decode('UTF-8')}),
font_size=36,
x=window.width//2, y=window.height//2, # same here, window on line 6
anchor_x='center', anchor_y='center')
else:
label = pyglet.text.Label('Music paused!', font_size=36, x=window.width//2, y=window.height//2, anchor_x='center', anchor_y='center')
label.draw()

window.flip() # This is overkill but ensures proper rendering at all times.

@window.event
def on_key_press(symbol, modifiers):
# Up and Down controls the volume for instance
if symbol == pyglet.window.key.UP:
player.volume = player.volume+0.1
elif symbol == pyglet.window.key.DOWN:
player.volume = player.volume-0.1

# Any key really will start/pause the playback
elif player.playing:
player.pause()
else:
player.play()

pyglet.app.run()

关于linux - 在 Ubuntu 上使用 python 2.7 和 pyglet 的 Mp3 播放器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43332125/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com