<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">The following code should work (taken from <a href="https://stackoverflow.com/a/61296171/2001654">https://stackoverflow.com/a/61296171/2001654</a> ):<div><br></div><div><div><font face="monospace">import os</font></div><div><span style="font-family:monospace">from PyQt5 import QtCore, QtWidgets, QtMultimedia, QtMultimediaWidgets</span><br></div><div><span style="font-family:monospace">import sip</span><br></div><div><br></div><div><font face="monospace">class MainWindow(QtWidgets.QMainWindow):</font></div><div><font face="monospace"> def __init__(self, parent=None):</font></div><div><font face="monospace"> super(MainWindow, self).__init__(parent)</font></div><div><font face="monospace"> video_widget = QtMultimediaWidgets.QVideoWidget()</font></div><div><font face="monospace"> self.player = QtMultimedia.QMediaPlayer(</font></div><div><font face="monospace"> self, QtMultimedia.QMediaPlayer.VideoSurface</font></div><div><font face="monospace"> )</font></div><div><font face="monospace"> file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "test5.mkv")</font></div><div><font face="monospace"> self.player.setMedia(</font></div><div><font face="monospace"> QtMultimedia.QMediaContent(QtCore.QUrl.fromLocalFile(file))</font></div><div><font face="monospace"> )</font></div><div><font face="monospace"> self.player.setVideoOutput(video_widget)</font></div><div><font face="monospace"> self.player.play()</font></div><div><font face="monospace"> self.setCentralWidget(video_widget)</font></div><div><font face="monospace"><br></font></div><div><font face="monospace"> control = self.player.service().requestControl(</font></div><div><font face="monospace"> "org.qt-project.qt.mediastreamscontrol/5.0"</font></div><div><font face="monospace"> )</font></div><div><font face="monospace"> self.qcontrol = sip.cast(control, QtMultimedia.QMediaStreamsControl)</font></div><div><font face="monospace"> self.resize(640, 480)</font></div><div><font face="monospace"><br></font></div><div><font face="monospace"> def contextMenuEvent(self, event):</font></div><div><font face="monospace"> menu = QtWidgets.QMenu()</font></div><div><font face="monospace"> group = QtWidgets.QActionGroup(menu)</font></div><div><font face="monospace"> group.setExclusive(True)</font></div><div><font face="monospace"> index = 0</font></div><div><font face="monospace"> for i in range(self.qcontrol.streamCount()):</font></div><div><font face="monospace"> t = self.qcontrol.streamType(i)</font></div><div><font face="monospace"> if t == QtMultimedia.QMediaStreamsControl.AudioStream:</font></div><div><font face="monospace"> action = menu.addAction("Audio-{}".format(index))</font></div><div><font face="monospace"> action.setCheckable(True)</font></div><div><font face="monospace"> if self.qcontrol.isActive(i):</font></div><div><font face="monospace"> action.setChecked(True)</font></div><div><font face="monospace"> action.setData(i)</font></div><div><font face="monospace"> menu.addAction(action)</font></div><div><font face="monospace"> index += 1</font></div><div><font face="monospace"> action = menu.exec_(self.mapToGlobal(event.pos()))</font></div><div><font face="monospace"> if action is not None:</font></div><div><font face="monospace"> i = action.data()</font></div><div><font face="monospace"> self.qcontrol.setActive(i, True)</font></div></div><div dir="ltr"><br></div><div dir="ltr"><br></div>I tried the pyside alternative proposed in the link, but unfortunately I'm unable to successfully load the file on PySide due to the following error:</div><div dir="ltr"><div dir="ltr">ERROR: Caught a segmentation fault while loading plugin file:</div><div dir="ltr">/usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgsttypefindfunctions.so</div><div><br>The same file correctly loads on PyQt5 (but obviously there's no QMediaStreamsControl), so I suppose there's some problem with my installation of PySide.</div><div><br></div><div>The sample (test5.mkv) is available in the Matroska test files: <a href="https://github.com/Matroska-Org/matroska-test-files">https://github.com/Matroska-Org/matroska-test-files</a></div><div><br></div><div>Thank you,</div><div>Maurizio</div></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno dom 19 apr 2020 alle ore 10:17 Phil Thompson <<a href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 18/04/2020 19:06, Maurizio Berti wrote:<br>
> Il giorno sab 18 apr 2020 alle ore 14:24 Phil Thompson <<br>
> <a href="mailto:phil@riverbankcomputing.com" target="_blank">phil@riverbankcomputing.com</a>> ha scritto:<br>
> <br>
>> When I don't understand an API properly then I tend to leave it until<br>
>> somebody complains and then I've got someone more knowledgeable who I<br>
>> can ask about it.<br>
>> <br>
>> From what you say, all I need to do is to wrap the various <br>
>> QMediaControl<br>
>> sub-classes (all 39 of them). Is that right?<br>
>> <br>
> <br>
> It seems like so, but honestly I'm not an expert, I don't know if that<br>
> would be enough and, most importantly, I wouldn't be able to test it in <br>
> the<br>
> near future because I cannot update my current setups to newer PyQt<br>
> releases at the moment.<br>
> <br>
> Right now at least I know that it doesn't work because it's not been<br>
> implemented yet, but, of course, adding support for those classes could <br>
> be<br>
> a good thing, as I might be interested in using them in the future.<br>
<br>
Any chance you can send me a short script that *should* work and a test <br>
audio stream?<br>
<br>
Phil<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature">È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br><a href="http://www.jidesk.net" target="_blank">http://www.jidesk.net</a></div>