[PyQt] Playing an ogg file with QtMultimedia?

Brandon Keith Biggs brandonkeithbiggs at gmail.com
Wed Sep 9 17:40:02 BST 2015


Hello,
I have played my sound file in pygame, VLC and Audacity.
What is Slicer?
I am on Windows 7 64 Bit, so that may be part of the problem. Is there 
another audio type other than ogg that is more multiplatform? (That is 
not wav!)
Here is my not working code:

import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtCore import QUrl
from PyQt5 import QtMultimedia
from qt_tools import key_text

class Window(QWidget):
     def __init__(self):
         super().__init__()
         self.player = QtMultimedia.QMediaPlayer(self)
         self.sound = 
QtMultimedia.QMediaContent(QUrl.fromLocalFile("draw_sword.ogg"))
         self.player.setMedia(self.sound)
         self.player.setVolume(100)
         self.show()

     def keyPressEvent(self, e):
         key = key_text(e.key())
         if key == "space":
             print(self.player.errorString())
             self.player.play()

app = QApplication(sys.argv)
window = Window()
sys.exit(app.exec_())


Brandon Keith Biggs <http://www.brandonkeithbiggs.com/>
On 9/9/2015 4:46 PM, Saeed Mahdizadeh Bakhshmand wrote:
>
> This problem is solved, thanks for your follow up, so I tried it in a 
> later nightly version of Slicer and it worked fine.
>
> On Sep 9, 2015 10:11 AM, "Rembrand (daxLAB Limitted)" 
> <rembrand at daxlab.com <mailto:rembrand at daxlab.com>> wrote:
>
>
>     Did you try to play the same .ogg file with another (external)
>     player?
>
>     I did play multimedia files on Linux with QtMultimedia succesfully
>      but I have to check and see if it was .ogg (I believe I did). I
>     also used the fromLocalFile option for that to be sure.
>     I'm not sure but I think  that I read  that spaces inside the path
>     to the codecs can cause problems.
>
>     Best regards,
>     Rembrand
>
>     Cell phone: +31 646.224.526
>     Email: rembrand at daxlab.com <mailto:rembrand at daxlab.com>
>     Sent from my smart phone.
>
>
>
>     -------- Original message --------
>     From: pyqt-request at riverbankcomputing.com
>     <mailto:pyqt-request at riverbankcomputing.com>
>     Date: 09/09/2015 13:00 (GMT+01:00)
>     To: pyqt at riverbankcomputing.com <mailto:pyqt at riverbankcomputing.com>
>     Subject: PyQt Digest, Vol 134, Issue 9
>
>     Send PyQt mailing list submissions to
>     pyqt at riverbankcomputing.com <mailto:pyqt at riverbankcomputing.com>
>
>     To subscribe or unsubscribe via the World Wide Web, visit
>     https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>     or, via email, send a message with subject or body 'help' to
>     pyqt-request at riverbankcomputing.com
>     <mailto:pyqt-request at riverbankcomputing.com>
>
>     You can reach the person managing the list at
>     pyqt-owner at riverbankcomputing.com
>     <mailto:pyqt-owner at riverbankcomputing.com>
>
>     When replying, please edit your Subject line so it is more specific
>     than "Re: Contents of PyQt digest..."
>
>
>     Today's Topics:
>
>        1. Usage of active-x based camera viewer components (Carl Wolff)
>        2. Re: Playing an ogg file with QtMultimedia? (Brandon Keith Biggs)
>        3. Return type Qlist<QModelIndex> is ignored because it is
>           unknown to PythonQt (Saeed Mahdizadeh Bakhshmand)
>        4. Re: Return type Qlist<QModelIndex> is ignored because it is
>           unknown to PythonQt (Florian Bruhin)
>
>
>     ----------------------------------------------------------------------
>
>     Message: 1
>     Date: Tue, 8 Sep 2015 21:36:39 +0200
>     From: Carl Wolff <carl at wolff-online.nl <mailto:carl at wolff-online.nl>>
>     To: pyqt at riverbankcomputing.com <mailto:pyqt at riverbankcomputing.com>
>     Subject: [PyQt] Usage of active-x based camera viewer components
>     Message-ID:
>     <CA+89xzSKqZK_CwUWQfmYpAixiNBNQs=ACtNZkisEif3vRgaW6A at mail.gmail.com <mailto:ACtNZkisEif3vRgaW6A at mail.gmail.com>>
>     Content-Type: text/plain; charset="utf-8"
>
>     Hello Group members
>
>     If I have an com / active-x based camera viewer library (in order
>     to create
>     a viewing pane in my pyqt based application) can I use
>     qaxcontainer for
>     that?
>
>     What are the pitfalls and things to be careful with?
>
>     Are there limitations?
>
>     Best regards
>     Carl.
>     -------------- next part --------------
>     An HTML attachment was scrubbed...
>     URL:
>     <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150908/d91bfe97/attachment-0001.html>
>
>     ------------------------------
>
>     Message: 2
>     Date: Tue, 8 Sep 2015 21:52:24 +0200
>     From: Brandon Keith Biggs <brandonkeithbiggs at gmail.com
>     <mailto:brandonkeithbiggs at gmail.com>>
>     To: pyqt at riverbankcomputing.com <mailto:pyqt at riverbankcomputing.com>
>     Subject: Re: [PyQt] Playing an ogg file with QtMultimedia?
>     Message-ID: <55EF3C78.3060305 at gmail.com
>     <mailto:55EF3C78.3060305 at gmail.com>>
>     Content-Type: text/plain; charset="windows-1252"; Format="flowed"
>
>       Hello,
>     > I get:
>     > "Unsupported media type."
>     > as the error.
>     >
>     > I found:
>     > http://stackoverflow.com/questions/15043620/cant-play-ogg-and-flac
>     >
>     > and installed the codecs from:
>     > http://www.xiph.org/dshow/
>     >
>     > I just ran the binary installer installing them into:
>     > C:\Program Files (x86)\Xiph.Org\Open Codecs\x64
>     >
>     > But I am still getting the unsupported media type.
>     > Thank you,
>     >
>     > Brandon Keith Biggs <http://www.brandonkeithbiggs.com/>
>     > On 9/4/2015 9:56 AM, Florian Bruhin wrote:
>     >> Hi,
>     >>
>     >> (also Cc-ing the list again as I don't think it was intended to
>     send
>     >> this off-list)
>     >>
>     >> * Brandon Keith Biggs<brandonkeithbiggs at gmail.com
>     <mailto:brandonkeithbiggs at gmail.com>> [2015-09-04 09:31:41 +0200]:
>     >>> Here is what I have, but it is silent and there is no error:
>     >>>
>     >>>          self.player = QtMultimedia.QMediaPlayer(self)
>     >>>          self.s =
>     QtMultimedia.QMediaContent(QUrl("sounds/my_sound.ogg"))
>     >> This should probably be QUrl.fromLocalFile(...) instead.
>     >>
>     >>>          self.player.setMedia(self.s)
>     >>>          self.player.play()
>     >>>
>     >>> Could there be some kind of dll that I need to put in my PyQt5
>     dir?
>     >> If a DLL was missing, Qt would probably terminate/abort.
>     >>
>     >> Some things to check:
>     >>
>     >> - .error()/.errorString()
>     >> - .volume() (in the example they do .setVolume(50))
>     >>
>     >> Florian
>     >>
>     >
>
>     -------------- next part --------------
>     An HTML attachment was scrubbed...
>     URL:
>     <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150908/a689efc2/attachment-0001.html>
>
>     ------------------------------
>
>     Message: 3
>     Date: Tue, 8 Sep 2015 17:51:45 -0400
>     From: Saeed Mahdizadeh Bakhshmand <saeedbakhshmand at gmail.com
>     <mailto:saeedbakhshmand at gmail.com>>
>     To: pyqt at riverbankcomputing.com <mailto:pyqt at riverbankcomputing.com>
>     Subject: [PyQt] Return type Qlist<QModelIndex> is ignored because it
>     is unknown to PythonQt
>     Message-ID:
>     <CAGdd0Q7Q7u4+yuagqUOo=6PAS+DzXJ4CZ=ASpc0y6sLS2UhJLA at mail.gmail.com <mailto:ASpc0y6sLS2UhJLA at mail.gmail.com>>
>     Content-Type: text/plain; charset="utf-8"
>
>     Hello All,
>
>     I am trying to obtain a list (indices) of selected cells in a
>     QTableView
>     using this script (in 3D slicer interface):
>
>     table = qt.QTableView()
>     ...
>     #setup of the table and adding models and items etc.
>     ...
>     select = table.selectionModel()
>     index = select.selectedIndexes()
>
>     and I get this error:
>
>     File "<console>", line 1, in <module>
>
>     ValueError: Called QList<QModelIndex> selectedRows(), return type
>     'QList<QModelIndex>' is ignored because it is unknown to PythonQt.
>     Probably
>     you should register it using qRegisterMetaType() or add a default
>     constructor decorator to the class.
>
>
>     Any hint on which way is better and how can I register an unknown
>     type in
>     PythonQt?
>
>
>     Best,
>
>     Saeed
>     -------------- next part --------------
>     An HTML attachment was scrubbed...
>     URL:
>     <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150908/60ae1d5e/attachment-0001.html>
>
>     ------------------------------
>
>     Message: 4
>     Date: Wed, 9 Sep 2015 06:22:12 +0200
>     From: Florian Bruhin <me at the-compiler.org
>     <mailto:me at the-compiler.org>>
>     To: pyqt at riverbankcomputing.com <mailto:pyqt at riverbankcomputing.com>
>     Subject: Re: [PyQt] Return type Qlist<QModelIndex> is ignored because
>     it is unknown to PythonQt
>     Message-ID: <20150909042212.GW18577 at tonks>
>     Content-Type: text/plain; charset="utf-8"
>
>     * Saeed Mahdizadeh Bakhshmand <saeedbakhshmand at gmail.com
>     <mailto:saeedbakhshmand at gmail.com>> [2015-09-08 17:51:45 -0400]:
>     > Any hint on which way is better and how can I register an
>     unknown type in
>     > PythonQt?
>
>     PythonQt != PyQt ;)
>
>     Florian
>
>     -- 
>     http://www.the-compiler.org | me at the-compiler.org
>     <mailto:me at the-compiler.org> (Mail/XMPP)
>        GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
>              I love long mails! | http://email.is-not-s.ms/
>     -------------- next part --------------
>     A non-text attachment was scrubbed...
>     Name: not available
>     Type: application/pgp-signature
>     Size: 819 bytes
>     Desc: not available
>     URL:
>     <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150909/56db31a4/attachment-0001.sig>
>
>     ------------------------------
>
>     Subject: Digest Footer
>
>     _______________________________________________
>     PyQt mailing list
>     PyQt at riverbankcomputing.com <mailto:PyQt at riverbankcomputing.com>
>     https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
>     ------------------------------
>
>     End of PyQt Digest, Vol 134, Issue 9
>     ************************************
>
>     _______________________________________________
>     PyQt mailing list PyQt at riverbankcomputing.com
>     <mailto:PyQt at riverbankcomputing.com>
>     https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
>
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150909/f8cd5dc8/attachment-0001.html>


More information about the PyQt mailing list