python - sound.seek() 没有。什么都没发生。我想为我的应用程序制作一个简单的 mp3 播放器
问题描述
sound.seek()
没有。什么都没发生。声音位置始终为 0。我想为我的应用程序制作一个简单的 mp3 播放器。我怎样才能让它正常工作。当我移动滑块标签时,文本和声音位置也应该移动。当音乐播放时,滑块光标也应该移动。这是我的代码:
def to_seconds(value):
a_string = str(int(value // 60))
b_string = str(int(value % 60))
if len(a_string) == 1:
a_string = '0' + a_string
if len(b_string) == 1:
b_string = '0' + b_string
return a_string + ' : ' + b_string
class Player(BoxLayout):
def __init__(self, **kwargs):
super(Player, self).__init__(**kwargs)
self.file = 'music_files/Billie_Eilish_-_Ocean_Eyes.mp3'
self.play = 'images/play.png'
self.palki = 'images/palki.png'
self.cursor = 'images/cursor.png'
self.sound = SoundLoader.load(self.file)
print(to_seconds(self.sound.length))
self.sl = Slider(orientation='horizontal',
min=0,
max=self.sound.length,
step=1,
padding=20,
background_width=40,
value_track=True,
value_track_color=(1, .1, .1, 1),
value_track_width=(5),
cursor_image=(self.cursor),
value=self.sound.get_pos()
)
self.sl.bind(value=self.slider_callback)
self.w1.add_widget(self.sl)
but1 = Button()
self.but2 = Button(background_normal=(self.play),
background_down=(self.play),
on_press=self.play_but_callback
)
but3 = Button()
self.gl.add_widget(but1)
self.gl.add_widget(self.but2)
self.gl.add_widget(but3)
self.lb = Label(font_size=35,
size_hint_x=.85,
text=to_seconds(self.sl.value),
halign='right',
valign='top'
)
self.al.add_widget(self.lb)
self.sl.value = self.sound.get_pos()
self.sound.play()
def slider_callback(self, intance, value):
print(value)
if self.sound:
self.sound.play()
self.sound.seek(int(value))
print(self.sound.get_pos())
self.lb.text = to_seconds(value)
解决方案
推荐阅读
- html - 在角度 8 中更改复选框检查值时触发 ng 更改
- pipe - 使用管道的素数
- python - 我无法使用一种方法删除 s3 对象,但我可以使用另一种方法删除。(obj.delete 与 delete_object)
- slurm - Snakemake slurm 输出文件重定向到新目录
- vnc - 为什么在 VNC 中运行的应用程序显示在主机而不是客户端?
- java - 在 MIPS 中将十六进制转换为十进制
- reactjs - 在 componentDidUpdate 中无法访问状态
- android - 当我移动到另一个活动并返回时,片段 editText 数据被清除
- javascript - 为什么我在屏幕上看不到我的应用程序?反应.js
- python - 如何在银河坐标系中绘制地球观测站的视野?