Hi everyone
I'll start by saying that I'm just starting out with Raspberry and Python programming, but let's get to the problem.
I'm creating a control interface for my audio preamplifier (tube) to control the different parameters such as volume, balance, inputs etc.
To this interface, created in Python and using PyQt5 libraries, I want to add the way to play audio files.
To do this I'm trying to use QMediaPlayer imported from PyQt5 QMultimedia.
Problem that when executing the "play" command it does not play anything and crashes the Raspberry.
The audio output selected on the Raspberry is that of the headphones, (if I use VLC or other players it works correctly).
I'm using a Raspberry PI4B Rev 1.2, Thonny python editor 3.3.0, python 3.7.3 (32 bit).
Thank you all for the help, below is the code in Python:
the functions are activated by the buttons located in the main window and done as follows:
self.ui.Button_mp_play.clicked.connect(self.mp.play_song)
I'll start by saying that I'm just starting out with Raspberry and Python programming, but let's get to the problem.
I'm creating a control interface for my audio preamplifier (tube) to control the different parameters such as volume, balance, inputs etc.
To this interface, created in Python and using PyQt5 libraries, I want to add the way to play audio files.
To do this I'm trying to use QMediaPlayer imported from PyQt5 QMultimedia.
Problem that when executing the "play" command it does not play anything and crashes the Raspberry.
The audio output selected on the Raspberry is that of the headphones, (if I use VLC or other players it works correctly).
I'm using a Raspberry PI4B Rev 1.2, Thonny python editor 3.3.0, python 3.7.3 (32 bit).
Thank you all for the help, below is the code in Python:
Code:
import sysfrom PyQt5.QtWidgets import (QApplication, QWidget, QFileDialog)from PyQt5.QtMultimedia import (QMediaPlayer, QMediaContent, QMediaMetaData)from PyQt5.QtCore import (QUrl, QTimer)class MusicPlayer (QWidget): def __init__(self): super().__init__() self.cur_sel=[] self.cur_path=[] self.current_songs = [] self.current_volume = 100 self.meta_Artist="" self.meta_title="" self.player = QMediaPlayer() self.player.setVolume(self.current_volume) def add_songs(self): files, _ = QFileDialog.getOpenFileNames( self, caption='Aggiungi brani', directory='./', filter='Audio Files (*.mp3)' ) if files: for file in files: self.current_songs.append(file) self.file=self.cur_path def play_song(self): song_url = QMediaContent(QUrl.fromLocalFile(self.current_songs[self.cur_sel])) self.player.setMedia(song_url) print("play MP") self.player.play() self.metadata() def metadata(self): if self.player.isMetaDataAvailable(): self.meta_Artist=self.player.metaData(QMediaMetaData.ContributingArtist) print("Artista: ",self.meta_Artist) self.meta_title=self.player.metaData(QMediaMetaData.Title) print("Titolo: ",self.meta_title) def stop_song(self): print("stop MP") self.player.stop() def pause_song(self): print("pause MP") self.player.pause()
self.ui.Button_mp_play.clicked.connect(self.mp.play_song)
Statistics: Posted by Amuro — Sat Apr 13, 2024 9:17 am