SoundLoader.seek() работает некорректно в Kivy, Python

Не работает метод seek() (звук не перематывается). Что делать? Пишу аудиоплеер (пару дней назад начал). Код:

import kivy
from kivymd.uix.slider import MDSlider
from kivymd.uix.button import MDFillRoundFlatButton, MDIconButton, MDRoundFlatIconButton 
from kivymd.uix.label import MDLabel
from kivy.core.audio import SoundLoader
from kivymd.uix.floatlayout import MDFloatLayout
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.app import MDApp
import os
from mutagen.mp3 import MP3
import eyed3
def get_mp3_metadata(file_path):
    audio2 = eyed3.load(file_path)
    # Получаем название песни
    return str(audio2.tag.title)  
def get_mp3_length(file_path):
    audio = MP3(file_path)

    if round(audio.info.length%60) < 10:
        string = str(int(audio.info.length//60)) + ':0' + str(round(audio.info.length%60))
    else:
        string = str(int(audio.info.length//60)) + ':' + str(round(audio.info.length%60))              
    return string, audio.info.length
class MusicPlayer(MDApp):
    def build(self):
        lay = MDFloatLayout()
        self.sound = None
        self.volume = 5.0
        slider = MDSlider(min=0, max=get_mp3_length('song.mp3')[1], value=0, pos_hint={'center_x': 0.5, 'center_y': 0.5}, size_hint=(0.8, 0.06), on_touch_up=self.on_slider_touch_up)
        lay.add_widget(slider)
        button = MDRoundFlatIconButton(text='Play Music', 
                                       on_release=self.toggle_music,
                                       pos_hint={'center_x': 0.5, 'center_y': 0.4},
                                       size_hint=(0.8, 0.06))
        leng = MDLabel(text='Audio Length: '+get_mp3_length('song.mp3')[0], 
                                       pos_hint={'center_x': 0.5, 'center_y': 0.6},
                                       size_hint=(0.8, 0.06))
        lay.add_widget(button)
        lay.add_widget(leng)
        #volume = MDFillRoundFlatButton(text='Volume', 
        #                               on_release=self.change_volume, 
        #                               pos_hint={'center_x': 0.5, 'center_y': 0.4},
        #                               size_hint=(0.8, 0.06))
        #lay.add_widget(volume)
        return lay
    def on_slider_touch_up(self, instance, value):
        if self.sound:
            self.sound.stop()
            self.sound = SoundLoader.load('song.mp3')
            self.sound.seek(int(instance.value))  
            self.sound.play() 
            print(value)
            print(self.sound.get_pos())
    def toggle_music(self, instance):
        if self.sound == None:
            self.sound = SoundLoader.load('song.mp3')
            self.sound.play()
            instance.text = 'Stop Music'  # Change button text to 'Stop Music'
        else:
            self.sound.stop()
            self.sound = None
            instance.text = 'Play Music'  # Change button text to 'Play Music'

    #def change_volume(self, instance):
    #    if self.sound is not None:
    #        if self.volume == 5.0:
    #            self.volume = 5.0
    #            self.sound.volume = self.volume
    #        else:
    #            self.volume = 5.0
    #            self.sound.volume = self.volume

if __name__ == '__main__':
    print('Started successfully')
    MusicPlayer().run()

Ответы (0 шт):