Python Forum
PySide2 and QMediaPlayer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PySide2 and QMediaPlayer
#1
I've been trying to get mp3 files to play using QMediaPlayer with no success. Can anyone shed some light on what I'm missing?
The basic code. If you wish to see all the code, let me know.
According to the examples this works. I get no sounds or errors.
Thanks.

#! /usr/bin/env python3

from PySide2.QtCore import QUrl
from PySide2.QtMultimedia import QMediaPlayer, QAudio

player = QMediaPlayer()
player.setMedia(QUrl.fromLocalFile('My Music/here.mp3'))
player.setVolume(70)
player.play()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#2
I think, not sure of this, pyside2 was written for python 2.7.
There is a pyside6 version available pip install PySide6
see: https://pypi.org/project/PySide6/
Reply
#3
What is your OS ?
Reply
#4
doc page for pyside6: https://doc.qt.io/qtforpython/

Show your OS for Axel_Erfurt, he may have an example for you.
Reply
#5
os is windows 10
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#6
Just because all you want to do is play a mp3 file it doesn't mean you can skip the setup work of making an application or running it.
from PySide2.QtCore import QUrl
from PySide2.QtMultimedia import QMediaPlayer, QAudio
import PySide2.QtWidgets as QtWidgets
import sys
 
app = QtWidgets.QApplication(sys.argv)  # Does all the setup work required to use Qt
player = QMediaPlayer()
player.setMedia(QUrl.fromLocalFile('Hotel California.mp3'))
player.setVolume(70)
player.play()
sys.exit(app.exec_())  # Stops program from exiting
This example will not work for PySide6 which has several changes to the media player.

Now stop bothering me. I'm chillin to the Eagles
Reply
#7
Thanks for the example deanhystad but, still not hearing anything on windows 10 os. I'm going to give it a try on my linux os.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#8
I ran the program on My Windows 10 machine and it works. Are you sure about the file location? Should get an error if that happens. Have you verified that the mp3 file is playable?
Reply
#9
The file is playable. On my linux did get three errors.
GStreamer; Unable to pause - "file:here.mp3"
GStreamer; Unable to play - "file:here.mp3"
Error: "Could not open resource for reading."

Maybe a path problem?
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#10
Is 'Hotel California.mp3' in the script folder?

If not try the full path to 'Hotel California.mp3'
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,345 Mar-02-2019, 08:46 PM
Last Post: mame
  Pyside2 darktitan 2 4,043 Aug-08-2018, 06:09 PM
Last Post: darktitan
  [PySide2][PyQt5] update QTableView cpuin 0 5,250 Mar-07-2018, 10:20 PM
Last Post: cpuin
  Problem on installing PySide2 on Mac cpuin 5 4,989 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