I'm using PyQt5 to make a music player. I wanna know how to move QSlider over time.
I wrote some code but when i run it the program crashes. I wanna know how to implement it.
I searched for this in google and read the documentation but I didn't find anything.
This is some of my code:
from pygame import mixer
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from mutagen.mp3 import MP3
import sys
import time
mixer.init()
file = ""
playing = False
Volume_value = 100
Song_time = 0
Song_current_time = 0
class Ui_mainWindow(object):
def setupUi(self, mainWindow):
global Volume_value
global Song_time
self.SongProgress = QtWidgets.QSlider(self.centralwidget)
self.SongProgress.setGeometry(QtCore.QRect(299, 130, 241, 20))
self.SongProgress.setOrientation(QtCore.Qt.Horizontal)
self.SongProgress.setObjectName("SongProgress")
if playing == True:
self.Get_current_time()
def Get_length_of_file(self):
global file
global Song_time
audio = MP3(file[0])
Song_time = audio.info.length
# Sets the Songs time to SongProgress
self.SongProgress.setMaximum(int(Song_time))
def Get_current_time(self):
global Song_current_time
global playing
t = int(Song_current_time)
if playing:
for i in range(t):
self.SongProgress.setValue(i)
time.sleep(1)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
mainWindow = QtWidgets.QMainWindow()
ui = Ui_mainWindow()
ui.setupUi(mainWindow)
mainWindow.show()
sys.exit(app.exec_())