PyQt music player widget
PyQt5 >= 5.8
python -m pip install pyqt-music-player-widget
This is using audioread
to get the full length of the media.
- Methods -
play()
,pause()
,stop()
- Signals -
played(bool)
,positionUpdated(int)
,durationUpdated(int)
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QFormLayout
from pyqt_find_path_widget import FindPathWidget # https://github.com/yjg30737/pyqt-find-path-widget.git
from pyqt_music_player_widget import MusicPlayerWidget
class MusicPlayerExample(QWidget):
def __init__(self):
super().__init__()
self.__initUi()
def __initUi(self):
self.__findPathWidget = FindPathWidget()
self.__findPathWidget.setExtOfFiles('Audio Files (*.mp3)')
self.__findPathWidget.added.connect(self.__added)
lay = QFormLayout()
lay.addRow('Audio File', self.__findPathWidget)
lay.setContentsMargins(0, 0, 0, 0)
pathFindWidget = QWidget()
pathFindWidget.setLayout(lay)
self.__musicPlayerWidget = MusicPlayerWidget()
lay = QVBoxLayout()
lay.addWidget(pathFindWidget)
lay.addWidget(self.__musicPlayerWidget)
self.setLayout(lay)
def __added(self, filename: str):
self.__musicPlayerWidget.setMedia(filename)
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
player = MusicPlayerExample()
player.show()
sys.exit(app.exec_())
Result