Python Forum
PySide2 and QMediaPlayer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PySide2 and QMediaPlayer
#11
yes, the mp3 file is in the same folder
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#12
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.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#13
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
Reply
#14
Still not hearing sound. I will hook my speakers up in a little while and see if it's because I'm using headphones.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#15
I can hear wav files. Maybe I don't have the right codec to play mp3 files.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#16
Do you have gstreamer plugins and libqt5multimedia5-plugins ?

find out with

dpkg -l libqt5multimedia5-plugins

dpkg -l | grep gstreamer
Reply
#17
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.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#18
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
Axel_Erfurt likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#19
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
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#20
Any idea how to view the playlist?
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter vs Pyside2 twallace51 1 3,128 Apr-21-2019, 05:16 PM
Last Post: Larz60+
  PySide2 with QtQuick & pyInstaller --> big executeable mame 3 4,341 Mar-02-2019, 08:46 PM
Last Post: mame
  Pyside2 darktitan 2 4,042 Aug-08-2018, 06:09 PM
Last Post: darktitan
  [PySide2][PyQt5] update QTableView cpuin 0 5,248 Mar-07-2018, 10:20 PM
Last Post: cpuin
  Problem on installing PySide2 on Mac cpuin 5 4,983 Feb-03-2018, 08:40 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020