QMediaPlayer does provide a stream of the audio data which is playing

Heads up! You've already completed this tutorial.

johnh100008948 | 2020-12-07 16:42:45 UTC | #1

From Martin Fitzpatrick's https://www.pythonguis.com/tutorials/failamp-multimedia-player/

He states that "QMediaPlayer does provide a stream of the audio data which is playing"

I have been trawling the docs all day, but can not find the stream. I intend to add a decibel meter to Martin's project.

Any ideas?

Thanks for any advice.


martin | 2021-05-07 07:49:29 UTC | #2

Hi @johnh100008948 welcome to the forum.

This is a nice project, I mentioned it on the tutorial as it was something i was planning to do but not yet got around to. Looking at it now, I'm not sure how to go about it either.

  1. the "stream" I mentioned there might in fact be the stream that's available when loading from an audio stream -- I think you can see the current data/access the stream as a file device. But that doesn't really help for showing what is currently playing.
  2. there is an example of an equalizer on the Qt website (this is QML but comparable). This looks promising until you realise they actually pre-calculate the bars loading them in via a separate file.

But all is not lost. There is actually a very nice PyQt5 media player with graphic equalizer called Milkplayer. If you look at the visualizer code what they do there is open the same file in a separate thread using pydub. The QMediaPlayer current positions are used to extract regions of the audio, which is then processed to generate the equalizer.

You could do something similar, and just return the total amplitude instead -- Each AudioSegment in pydub has a . dBFS property which gives you the loudness.

Hope that helps? I'll update the tutorial when I'm back in the office next week.


Packaging Python Applications with PyInstaller by Martin Fitzpatrick — This step-by-step guide walks you through packaging your own Python applications from simple examples to complete installers and signed executables.

More info Get the book

Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

QMediaPlayer does provide a stream of the audio data which is playing was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt.