QMediaPlayer can't play MP3's - c++

I need to build a simple mediaplayer for university using QT and I hit a wall.
Everytime I try to play a file (mp3, wav, doensn't matter) I'll just get
DirectShowPlayerService::doSetUrlSource: Unresolved error code 80070020
with every file. The files are not broken, every other player can play them.
It used to work (reading the tags, displaying them and actually playing the file) up until I would go ahead and add a album-artwork to display. The standard QMediaPlayer is used in this project.
I don't quite know where it might have gone wrong, it just stopped working all of a sudden...
I'm on QT 5.2.3 if that's of any help.
Thanks!

Related

WAV file with QML SoundEffect audio playback is distorted

My first go at using SoundEffect with QML, and I'm getting mixed results with no clear understanding of why. I can successfully use QML SoundEffect in user interface within an embedded C++ device. The thing I cannot solve is why some WAV files will play perfectly clear, and some will not.
I'm certain my code is correct...its something about how the audio is interpreted. I cannot share the WAV files I'm using...but here's what's happening:
I have two WAV files:
wav_file1_that_works.wav (which is 83kb)
and
wav_file2_that_does_not work.wav (which is 110kb)
Both of these files play just fine in VLC or Media Player or whatever. But when ran through the QML function to play as a feedback for touch on the device, the first WAV file plays just fine, while the second one does not. It does not appear to be a hardware issue as this same issue comes up exactly the same when working on virtual environment. I'm suspecting there is some limitation to using WAV audio within the QT/QML environment? But I cannot find any limits in the documentation. My only suspicion is the file size, or some other specific sound file requirement.
First I declare the sound link to the file:
SoundEffect {
id: playSound
source: "qrc:/wav_file2_that_does_not work.wav"
}
Then on the UI event it's played (not the exact code, but the event certainly works like this:
MyUiItem {
onMyUiTouched: {
playSound.play();
}
}
and file 1 plays perfectly, and file 2 plays, but with a very distorted scratchy sounds.
I probably don't know enough about how WAV file encoding works, but on the surface both files seems to be encoded correctly.
I solved this by refactoring how the app compiles as my WAV file was getting compressed. So unfortunately this was something I discovered that if I let my enterprise deployment system do its thing it compresses everything including all multi-media unless I apply certain parameters to not compress. And so now this works. Thanks for the help.

OpenAL C++ on Linux

I just need a simple program which allows me to play and stop an audio file. I'm guessing OpenAL is the way to go? All I need is this functionality - start audio file with spacebar and stop audio file with a second press of the spacebar. I notice the OpenAL documentation is quite involved. Can someone point me to something really simple in order to just get the start/stop functionality of a .wav file?
OpenAL may not be the simplest choice. If you use a gui-framework like QT, check for what their ecosystems provide for playing sound (e.g. qsound). Another choice may be Allegro which may feel more straightforward.
For OpenAL, there is a working example to play a wav in the example repositories. Playback can be paused using alSourcePause.
Edit:
For choosing libraries I like to consult Awesome-cpp. The simple_playback.c example of mini_al looks extremely straightforward. Simply use mal_device_stop(&device) to pause the running playback and mal_device_start(&device) to continue. Works perfectly on my machine and seems very portable.

Changin mp3 speed in Qt and C++ [QMediaPlayer]

I'm trying to develop a little application in which you can load a mp3 file and play it in variable speeds! (I know it already exists :-) )
I'm using Qt and C++. I already have the basic player but I'm stuck with the rate thing, because I want to change the rate smoothly (like in Mixxx) without stopping the playback! The QMediaPlayer always stops if I change the value and creates a gap in the sound. Also I don't want the pitch to change!
I already found something called "SoundTouch" but now I'm completely clueless what to do with it, how to process my mp3 data and how to get it to the player! The "SoundTouch" Library is capable of doing what I want, i got that from the samples on the homepage.
How do I have to import the mp3 file, so I can process it with the SoundTouch functions
How can I play the output from the SoundTouch function? (Perhaps QMediaPlayer can do the job?)
How is that stuff done live? I have to do some kind of stream I guess? So I can change the speed during play and keep on playing without gaps. Graphicaly in my head it has to be something that sits between the data and the player, where all data has to go through live, with a small buffer (20-50 ms or so) behind to avoid gaps during processing future data.
Any help appreciated! I'm also open to any another solution then "SoundTouch" as long as I can stay with Qt/C++!
(Second thing: I want to view a waveform overview aswell as moving part of it (around actual position of the song), so I could also use hints on how to get the waveform data)
Thanks in advance!
As of now (Qt 5.5) this is impossible to do with QMediaPlayer only. You need to do the following:
Decode the audio using GStreamer, FFMpeg or (new) QAudioDecoder: http://doc.qt.io/qt-5/qaudiodecoder.html - this will give you raw PCM stream;
Apply SoundTouch or some other library to this raw data to change the pitch. If GPL is ok, take a look at http://nsound.sourceforge.net/examples/index.html, if you develop proprietary stuff, STK might be a better choice: https://ccrma.stanford.edu/software/stk/
Output the modified data into audio device by using QAudioOutput.
This strategy uses Qt as much as possible, and brings you the best platform coverage (you still lose Android though as it does not support QAudioOutput)

UDP video using QMediaplayer library

I've been playing around the QMediaplayer library. I was curious about how it would work with some streaming video source, so I've used VLC to stream some videos using udp protocol.
To make a quick test, I've used the Qt example named MediaPlayer example. As the example is designed to work only with offline files, I've added on dumb function on the Player implementation.
void setM(QUrl url){player->setMedia(url);player->play();}
Then, on the main.cpp file I call this function like this:
...
player.setM(QUrl("udp://239.1.1.1:1234"));
return app.exec();
What this do is start to reproducing the stream source once the program is read.
The problem here is that Qt through me the following error:
DirectShowPlayerService::doSetUrlSource: Unresolved error code 800c000d
To do this with local files and http streaming and it works... but when I tried with UDP or RTP I always get the same error.
I've spent few hours looking for more information, but always get the same response... use QMLVLC... For example, look this.
Does anyone tried this before? What's is wrong here?
PD: I know that there is a VLC plugging to make this work, but I would like make this work only with Qt (or at least, understand what is happening here).
PD2: I'm on windows 8.1, Qt 5.5 (mingw 4.9.2) and I have all the important codecs installed.
Thanks in advance,
UPDATE
Finally, I manage to deal with the new http://code.qt.io and here is the code I suspect is blocking udp (and others) protocols-> here.
Maybe, only "http" and "https" are accepted as valid stream sources on Directshowsservice... I'll try to get some extra time this week to recompile just the multimedia module for windows in order to add udp procotol to the function doSetUrlSource and see what happens. If anyone test it first, please let me know here!
UPDATE 2
First of all, I suspect QMediaPlayer couldn't reproduce UDP/RTP content because the AddFilter method... Anyway, http,https and rtsp works perfectly.
Secondly, I've found some strange behavior over udp protocol.
I'm using "udp://#239.1.1.1:1234" as test multicast direction. The strange thing is that during one test I put this direction by mistake "udp://#239.1.1.1:1234z" and this time no error has been through. It seems that the direction needs to contain a letter.

Play and pause an .wav or .mp3 file on windows

I am working on a console application where i have to deal with multiple sound file with all of same type(.wav or .mp3). I have the option to chose between the two.
I can play the sound fine using PlaySound() function but i need some extra features.
I need pausing the sound and then play from the position where it paused last time.
OR
Set a time from where playing should start and time for which it should play.
1 of the two options will do the job.
I am working on windows with DEV C++ compiler.
Any help and ideas?
Use the Windows Media Player activeX control for anything more sophistcated than straight playing of a WAV file. It is far easier.
See "Using the Windows Media Player Control in a C++ Program" on MSDN:
http://msdn.microsoft.com/en-us/library/windows/desktop/dd564580(v=vs.85).aspx