Skip to content

yjg30737/pyqt-music-player-widget

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyqt-music-player-widget

PyQt music player widget

Requirements

PyQt5 >= 5.8

Setup

python -m pip install pyqt-music-player-widget

Included Packages

This is using audioread to get the full length of the media.

Method/Signal Overview

  • Methods - play(), pause(), stop()
  • Signals - played(bool), positionUpdated(int), durationUpdated(int)

Example

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

image