Oct-10-2021, 04:41 PM
Pages: 1 2
Oct-10-2021, 05:11 PM
I'm using headphones instead of speakers. Wonder if that may have something to do with it? All other video and audio files play through the headphones though.
Ok, I can hear wav files. Maybe I don't have the right codecs.
Ok, I can hear wav files. Maybe I don't have the right codecs.
Oct-10-2021, 05:24 PM
You must set QMediaContent and use the full path
from PySide2.QtCore import QUrl from PySide2.QtMultimedia import QMediaPlayer, QMediaContent import PySide2.QtWidgets as QtWidgets import sys app = QtWidgets.QApplication(sys.argv) # Does all the setup work required to use Qt player = QMediaPlayer() media_content = QMediaContent(QUrl.fromLocalFile('/tmp/test.mp3')) # use full path here player.setMedia(media_content) player.setVolume(70) player.play() sys.exit(app.exec_()) # Stops program from exiting
Oct-10-2021, 06:56 PM
Still not hearing sound. I will hook my speakers up in a little while and see if it's because I'm using headphones.
Oct-10-2021, 07:00 PM
I can hear wav files. Maybe I don't have the right codec to play mp3 files.
Oct-11-2021, 08:30 AM
Do you have gstreamer plugins and libqt5multimedia5-plugins ?
find out with
find out with
dpkg -l libqt5multimedia5-plugins
dpkg -l | grep gstreamer
Oct-11-2021, 03:52 PM
Quote:Do you have gstreamer plugins and libqt5multimedia5-plugins ?
find out with
dpkg -l libqt5multimedia5-plugins
dpkg -l | grep gstreamer
Yes, I have those installed on my linux os. As with the windows os, I can here the wav files. Just cant get the mp3 files to work.
Oct-11-2021, 04:27 PM
The solution was having to check the player state. so I did
from PySide2.QtCore import QUrl, QDir from PySide2.QtMultimedia import QMediaPlayer, QMediaContent import PySide2.QtWidgets as QtWidgets import sys app = QtWidgets.QApplication(sys.argv) # Does all the setup work required to use Qt player = QMediaPlayer() file = 'here.mp3' dir = QDir() media_content = QMediaContent(QUrl.fromLocalFile(f'{dir.currentPath()}/{file}')) # use full path here print(player.state()) player.setMedia(media_content) player.setVolume(70) if player.state() == player.StoppedState: # Check if player state is stopped player.play() sys.exit(app.exec_()) # Stops program from exiting
Oct-11-2021, 05:15 PM
This also works. Guess I just has an error in my coding.
from PySide2.QtCore import QUrl, QDir from PySide2.QtMultimedia import QMediaPlayer, QMediaContent, QMediaPlaylist import PySide2.QtWidgets as QtWidgets import sys app = QtWidgets.QApplication(sys.argv) # Does all the setup work required to use Qt player = QMediaPlayer() path = QDir().currentPath() url = QUrl() file = url.fromLocalFile(f'{path}/here.mp3') playlist = QMediaPlaylist(player) playlist.addMedia(QMediaContent(file)) player.setPlaylist(playlist) player.play() sys.exit(app.exec_()) # Stops program from exiting
Oct-11-2021, 05:26 PM
Any idea how to view the playlist?
Pages: 1 2