Answer the question
In order to leave comments, you need to log in
How to get rid of the beep sound before starting to play an mp3 file through a PyQt 5 module?
My little code creates a play_btn button on the main application window. This button is associated with the play_song() method of the MyWindow class. The play_song() method sets the source for the player to play. In this case, the source is the self.list element, which stores paths to mp3 files.
Clicking on the play_btn button does start the song playing, but there may be a short electronic sound before that. This sound is independent of the audio file to be played. It began to appear after installing the latest version of the K-Lite codec pack . Codecs have become necessary for me, because. some mp3 files refused to be played by the PyQt 5 module. Audio files that were not played before the codecs were installed now startbe played without this sound . Before starting playback of audio files that were played before the codecs were installed, this sound appears.
Please tell me how can I get rid of this beep? The method of trying to cut off the beginning of the composition, I now know, it does not quite suit me.
from PyQt5 import QtCore, QtWidgets, QtMultimedia
class MyWindow(QtWidgets.QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.list = ['1.Papercut.mp3', '13.Numb.mp3']
self.player = QtMultimedia.QMediaPlayer()
self.box = QtWidgets.QGridLayout(self)
play_btn = QtWidgets.QPushButton('Play', clicked = self.play_song)
self.box.addWidget(play_btn, 0, 0)
# Воспроизведение
def play_song(self):
self.player.setMedia(QtMultimedia.QMediaContent(QtCore.QUrl(self.list[1])))
self.player.play()
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
window = MyWindow()
window.setWindowTitle('MP3-player, PyQt5')
window.show()
sys.exit(app.exec_())
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question