Qt: no playback on linux - c++

I have tried (I think) every possible way of playing audio in a Qt project, none of which have worked:
QSound::play(...)
QMediaPlayer
QAudioOutput, from http://doc.qt.io/qt-4.8/qaudiooutput.html
None of these solutions play WAV or MP3, and I have tried loading the files from a resource (qrc:media/file.wav) or simply from disk (/full/path/to/file.wav).
I think the problem is with codecs. QAudioDevice::supportedCodecs() returns an empty list. I'm on a linux system that has no problems playing audio/video (Ubuntu 14.04, usually playing in VLC... that uses its own codecs?).
Playing with QSound (WAV & MP3):
QSoundEffect(pulseaudio): Error decoding source
QMediaplayer (WAV): nothing happens
QMediaplayer (MP3):
GStreamer; Unable to play - "qrc:media/lowtone.mp3"

Qt uses specific media backends for each platform(link is qt5, but it was the same in Qt4). From the error it looks like your version is using GStreamer.
Check if the gstreamer dev packages on your distribution are well installed, because QAudioDevice::supportedCodecs must return at least audio/pcm. Work on the package setup until your test program show pcm. See https://wiki.qt.io/Building_Qt_for_Linux
You may also need to install plugins (also dev packages) before being able to play wav or mp3 using phonon.

Related

Audio with QML - Unable to play a wav file

3 days I'm stuck with a tricky issue!
I've built an image for my embedded device based on a Colibri T20 board, using Yocto.
I"ve added Qt5, using X11 (because Tegra20 drivers from nvidia support hw accel only with X11...).
At this point, everything works fine.
I've also generated the respective SDK to build application for the respective platform..
Works fine.
I wrote a simple application to play audio file, very basic...just to play wav files...
It does not work. No sound output.
import QtMultimedia 5.5
Item {
...
Audio {
id: audioPlayer
source: "file:///opt/track.wav"
}
..
onClick() {
idPlayer.play()
}
}
This code works fine on my host linux.
But not on my Colibri.
Qt 5.5.1 was firstly built with ALSA, pulseaudio (gstreamer plugins...).
No outpût.
But in the linux, I can play the wav file using:
aplay /opt/track.wav
So I assume that my alsa driver are up-to-date.
Then, I 've recompiled Qt 5.5.1 without pulseaudio....
It does not work better :(
To be honnest, I'm not very experienced with alsa and pulseaudio matter. I'm very fustrated bzecause I don't understand what's happening under the abstracted layer of QtMultuimedia.
Any suggestion is welcome...This issue is simply driving me mad ;)

GStreamer encountered a general stream error in Qt5 raspberry pi

I'm trying to play a video using QtMediaPlayer in Raspberry pi 2 B. The source code is as follows:
QMediaPlayer *media;
QVideoWidget *video;
...
...
media = new QMediaPlayer(parent);
video = new QVideoWidget(parent);
media->setVideoOutput(video);
media->setMedia(QUrl::fromLocalFile("/home/pi/Desktop/test3.mp4"));
media->play();
But the result is a blank video screen and the following error:
** (Bus:2148): WARNING **: ffmpegcolorspace-vo: size 1105920 is not a
multiple of unit size 829440
Error: "GStreamer encountered a general stream error."
System Information
Running latest raspbian Jessie OS,
Installed Qt5.3,
Installed gstreamer0.10-plugins-good/bad/ugly/ffmpeg and
Installed Mpeg-2 License
Here is the video test3.mp4
I ran this code in Windows with Qt5 installed; it is working there. But it's not working in the Raspberry pi. Please tell me what I'm missing here.
Trying Pipe from Shell
Video playback on the Raspberry Pi is actually a bit of a tricky thing. The most common solution is to use OMXPlayer to play videos. It's a command line program, but there are lots of flags and repeated calls can control playback. All in all, it works pretty dang well for most smallish projects.
As far as actually using Qt, QMediaPlayer, and etc. I don't think you'll be able to make it work right out of the box. However, I found a blog that discusses this issue and has some Raspberry Pi firmware that fixes QtMultimedia support on the Raspberry Pi.

RTSP with Qt and VLC

I'm trying to use Qt5 to view a RTSP flow in a Windows 7 environment.
I read that QtMultimedia doesn't support RTSP (I did it well with videos of my computer and videos .mp4 on internet, but it doesn't seem to work with RTSP).
I can see the flow with VLC, so I came up with the idea of using vlc-qt
I found a sample code describing a basic usage of the library :
https://wiki.videolan.org/LibVLC_SampleCode_Qt
In order to make it work, I needed to include the libvlc.lib.
However I'm getting compiling errors such as:
QX11EmbedContainer not found
libvlc_exception_t not found
It seems that the libvlc_exception_t is deprecated in the newest version of VLC.
Are there any other possibilities? I wish I could only use Qt to include a live stream in a QWidget but I have not found anything.

Using Qt Media Player on Raspberry Pi 1

I have a project built using Qt5 which has to play a video. Just like in the videowidget sample code.
I've followed these instructions to build qt5 on my Pi. And it went just fine. But when I try to run any qt program that uses QMediaPlayer, I get the error message:
defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.mediaplayer"
Which means I don't have a backend to play the video, right? Is there any one that I can use which will with Qt, like ffmpeg? And how can I get it to work? Specially for h264 videos.
I've tried to install gstreamer as is told on this link, but it's not working. Will I have to rebuild the entire qt5 again?
P.S.: I have the raspberry pi 1 model B with raspbian installed.
Edit: As mentioned by Greenflow, I checked the ./configure log and saw that the GStreamer was compiled in, but the video apps are still not working...
The message on the log was like this:
GStreamer .............. yes (0.10)
And the message on Greenflow's log was like this:
GStreamer .............. yes (1.0)
Clearly it's another version of GStreamer, but is it the problem?
I've also found this post which says QtMultimedia on the Pi is rather useless, but the post is from 2013, so I'm not sure if it's really relevant. I'd like to have this app playing hardware accelerated videos on my Raspberry Pi, but I'm almost dropping the idea.
Anyways, thanks Greenflow for the head start.
Edit 2: Found this thread on the Qtcentre. Damn, this thing is not going to be easy to solve, I guess...
sudo apt-get install libqt5multimedia-plugins solved this for me.

using QMediaPlayer on Windows system with code compiled on Linux

A project of mine is written with Qt5/c++, using the QMediaPlayer class to read audio files. Everything's ok as long as I run this project on Linux.
Since I want to run my program on Windows, I use MXE to compile my code and create a binary file for Windows systems.
The program seems ok, except this problem with the QMediaPlayer class. When the program runs on a Windows system, I read this message :
defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.mediaplayer".
By googling around, I came to understand that the QMediaPlayer used several plugins, different on each platform. On Windows, The WMF plugin is Microsoft-only, DirectShow seems useless; others suggest to use other external plugins like portaudio, SdlAudio ou OpenAI.
How may I solve this problem ?
I found the problem and know how to fix it : according to this thread, just add the following line to your .pro file :
QTPLUGIN += dsengine qtmedia_audioengine