I'm using PyInstaller v5.6.2. I prescribe pyinstaller mp3pyqt6.py
, after which I add the necessary files to mp3pyqt6.spec
, updating the pyinstaller mp3pyqt6.spec
command. The console that comes with the application says: could not load multimedia backend "" QtMultimedia is not currently supported on this platform or compiler
Is there a way to solve this? Any alternatives to PyInstaller?
mp3pyqt6.py
from PyQt6.QtWidgets import QApplication, QWidget, QSizeGrip, QFileDialog
from PyQt6.QtCore import Qt, QUrl
from PyQt6 import uic, QtGui, QtWidgets, QtMultimedia
import png_icons6
import sys
import os
GLOBAL_STATE = 0
count = 0
play_count = 0
loop_count = 0
class App(QWidget):
def __init__(self):
super().__init__()
self.dragPos = None
self.ui = uic.loadUi('MP3Player6.ui', self)
self.ui.position = 0
self.ui.dial.setValue(50)
# Size Grip
self.size_grip = QSizeGrip(self.ui.f_status_right)
self.size_grip.setToolTip("Resize Window")
self.size_grip.setStyleSheet("QSizeGrip "
"{ width: 20px; height: 20px; margin: 5px } "
"QSizeGrip:hover "
"{ background-color: none; }")
# Title bar
self.setWindowFlag(Qt.WindowType.FramelessWindowHint)
self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
# Buttons
self.ui.btn_close.clicked.connect(lambda: self.close())
self.ui.btn_hide.clicked.connect(lambda: self.showMinimized())
self.ui.btn_maximize.clicked.connect(lambda: self.window_size())
self.ui.btn_play.clicked.connect(lambda: self.play_btn())
self.ui.dial.valueChanged.connect(self.dial_volume)
self.ui.btn_repeat.clicked.connect(lambda: self.loop_mp3())
# Player
self.player = QtMultimedia.QMediaPlayer()
self.audio_output = QtMultimedia.QAudioOutput()
# self.ui.postion = 0
self.player.positionChanged.connect(self.slider_pos)
self.player.durationChanged.connect(self.duration)
self.ui.horizontalSlider.sliderMoved.connect(lambda: self.set_position(self.ui.horizontalSlider.value()))
self.ui.horizontalSlider.valueChanged.connect(lambda: self.timer())
self.load_files()
def move_window(event):
if GLOBAL_STATE == 1:
self.window_size()
if event.buttons() == Qt.MouseButton.LeftButton:
pos = self.pos()
glpos = event.globalPosition().toPoint()
self.move(pos + glpos - self.dragPos.toPoint())
self.dragPos = event.globalPosition()
event.accept()
self.ui.f_title.mouseMoveEvent = move_window
self.show()
def mousePressEvent(self, event):
self.dragPos = event.globalPosition()
def window_size(self):
global GLOBAL_STATE
status = GLOBAL_STATE
if status == 0:
self.showMaximized()
self.ui.main_frame.setStyleSheet('background-color:'
' qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(42, 44, 111, 255), stop:0.522727 rgba(28, 29, 73, 255));'
' border-radius: 0px')
GLOBAL_STATE = 1
else:
self.showNormal()
self.ui.main_frame.setStyleSheet('background-color:'
' qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(42, 44, 111, 255), stop:0.522727 rgba(28, 29, 73, 255));'
' border-radius: 15px;')
GLOBAL_STATE = 0
def load_files(self):
spisok = []
for file in os.listdir(r"C:\Users\Michael\Мусор\Music"):
if file.endswith('.mp3'):
spisok.append(file)
self.ui.btn = QtWidgets.QPushButton()
font = QtGui.QFont()
font.setPointSize(20)
self.ui.btn.setFont(font)
self.ui.path = r'C:\Users\Michael\Мусор\Music\\' + str(file)
self.ui.btn.setText(file)
self.ui.url = QUrl.fromLocalFile(self.ui.path)
self.ui.verticalLayout_6.addWidget(self.ui.btn)
self.ui.btn.clicked.connect(lambda checked, g=self.ui.url, h=file: self.play_mp3_file(g, h))
def play_mp3_file(self, g, h):
global play_count
if play_count == 0:
self.player.setAudioOutput(self.audio_output)
self.player.setSource(g)
self.audio_output.setVolume(0.5)
self.player.setPosition(self.ui.position)
self.ui.dial.setValue(50)
self.ui.btn_play.setStyleSheet('QPushButton{image: url(:/пауза/png_icons/Пауза/icons8-pause-52.png);}QPushButton:hover{image: url(:/пауза/png_icons/Пауза/icons8-pause-52 (1).png);}QPushButton:pressed{image: url(:/пауза/png_icons/Пауза/icons8-pause-52 (2).png);}')
self.ui.label_song.setText(h)
self.ui.label_song.setFont(QtGui.QFont("Times", 10))
self.player.play()
play_count = 1
else:
self.player.stop()
self.player.setAudioOutput(self.audio_output)
self.player.setSource(g)
self.audio_output.setVolume(0.5)
self.player.setPosition(self.ui.position)
self.ui.dial.setValue(50)
self.ui.label_song.setText(h)
self.ui.label_song.setFont(QtGui.QFont("Times", 10))
self.ui.btn_play.setStyleSheet('QPushButton{image: url(:/пауза/png_icons/Пауза/icons8-pause-52.png);}QPushButton:hover{image: url(:/пауза/png_icons/Пауза/icons8-pause-52 (1).png);}QPushButton:pressed{image: url(:/пауза/png_icons/Пауза/icons8-pause-52 (2).png);}')
self.player.play()
def play_btn(self):
global play_count
if play_count == 0:
self.ui.btn_play.setStyleSheet('QPushButton{image: url(:/пауза/png_icons/Пауза/icons8-pause-52.png);}QPushButton:hover{image: url(:/пауза/png_icons/Пауза/icons8-pause-52 (1).png);}QPushButton:pressed{image: url(:/пауза/png_icons/Пауза/icons8-pause-52 (2).png);}')
self.player.play()
play_count = 1
else:
self.player.pause()
self.ui.btn_play.setStyleSheet('QPushButton {image: url(:/старт/png_icons/Старт/icons8-play-button-circled-50.png);}QPushButton:hover{image: url(:/старт/png_icons/Старт/icons8-play-button-circled-50 (1).png);}QPushButton:pressed{image: url(:/старт/png_icons/Старт/icons8-play-button-circled-50 (2).png);}')
play_count = 0
def dial_volume(self, i):
self.audio_output.setVolume(float(i/100))
def loop_mp3(self):
global loop_count
if loop_count == 0:
self.player.setLoops(-1)
loop_count = 1
self.ui.btn_repeat.setStyleSheet('QPushButton{image: url(:/повтор/png_icons/Повтор/icons8-update-left-rotation-48 (2).png);}QPushButton:hover{image: url(:/повтор/png_icons/Повтор/icons8-update-left-rotation-48 (1).png);}QPushButton:pressed{image: url(:/повтор/png_icons/Повтор/icons8-update-left-rotation-48.png);}')
else:
self.player.setLoops(1)
loop_count = 0
self.ui.btn_repeat.setStyleSheet('QPushButton{image: url(:/повтор/png_icons/Повтор/icons8-update-left-rotation-48.png);}QPushButton:hover{image: url(:/повтор/png_icons/Повтор/icons8-update-left-rotation-48 (1).png);}QPushButton:pressed{ image: url(:/повтор/png_icons/Повтор/icons8-update-left-rotation-48 (2).png);}')
def slider_pos(self, position):
self.ui.horizontalSlider.setValue(position)
def duration(self, duration):
self.ui.horizontalSlider.setRange(0, duration)
def set_position(self, position):
self.player.setPosition(position)
def timer(self):
total_milliseconds = self.player.duration()
total_seconds, total_milliseconds = divmod(total_milliseconds, 1000)
total_minutes, total_seconds = divmod(total_seconds, 60)
total_hours, total_minutes = divmod(total_minutes, 60)
elapsed_milliseconds = self.ui.horizontalSlider.value()
elapsed_seconds, elapsed_milliseconds = divmod(elapsed_milliseconds, 1000)
elapsed_minutes, elapsed_seconds = divmod(elapsed_seconds, 60)
elapsed_hours, elapsed_minutes = divmod(elapsed_minutes, 60)
self.ui.l_left_label.setText(f'{elapsed_minutes}:{elapsed_seconds}')
self.ui.l_right_label.setText(f'{total_minutes}:{total_seconds}')
if __name__ == '__main__':
app = QApplication(sys.argv)
application = App()
sys.exit(app.exec())
mp3pyqt6.spec
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(
['mp3pyqt6.py'],
pathex=[],
binaries=[],
datas=[('musicalnoteeightflat_105984.ico', '.'), ('png_icons6.py', '.'), ('MP3Player6.ui', '.')],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='mp3pyqt6',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='mp3pyqt6',
)
minimal reproducible example
import sys
from PyQt6 import uic
from PyQt6.QtCore import QUrl
from PyQt6 import QtMultimedia
from PyQt6.QtWidgets import QApplication, QWidget, QFileDialog
class App(QWidget):
def __init__(self):
super().__init__()
self.player = QtMultimedia.QMediaPlayer()
self.audio_output = QtMultimedia.QAudioOutput()
self.path = r'C:\Users\Michael\Мусор\Music\ac-dc-highway-to-hell-(best-muzon.cc).mp3'
self.player.setAudioOutput(self.audio_output)
self.player.setSource(QUrl.fromLocalFile(self.path))
self.audio_output.setVolume(20)
self.player.play()
if __name__ == '__main__':
app = QApplication(sys.argv)
application = App()
sys.exit(app.exec())
I already compiled a project using QtMultimedia on pyqt5, everything went well there. But in this player PyInstaller doesn't work.
I got it to work, and these are the steps I took to get it to run and compile.
main.py
.py -m venv venv && venv\scripts\activate
py -m pip install --upgrade pip pyinstaller PyQt6
pyinstaller -F main.py
venv\Lib\site-packages
folder and copy the PyQt6 directory to the top level directory next to main.py
and venv
main.spec
set the datas=[('./PyQt6', './PyQt6')]
pyinstaller main.spec
Once it compiles the executable should run. It pops a few warnings for me, but otherwise it does what its supposed too.