QAudioDeviceInfo finds no default audio device on Ubuntu - c++

I am trying to run the basic example from the QAudioDeviceInfo class reference, but Qt is not finding a default audio device.
Running this code shows no output:
foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput))
qDebug() << "Device name: " << deviceInfo.deviceName();
I'm running Qt Creator 2.7.1 with Qt 5.0.2 on Ubuntu 13.10. Qt Multimedia was installed via apt-get. My pro file has QT += multimedia. My header file includes:
#include <QAudio>
#include <QAudioOutput>
#include <QAudioDeviceInfo>
Any ideas as to what I might be doing wrong?

It was fixed with a simple command:
sudo apt-get install libqt5multimedia5-plugins
Qt Multimedia requires this plugin package for audio backend support.

Had same issue in windows. Fixed it by replacing Qt5Multimedia.dll in \Python34\Lib\site-packages\PyQt* with one from \Qt\Tools\QtCreator\bin.
Spend some time finding solution so decided to leave it here.

Related

Error on QT5.5 camera preview

I'm trying to use a camera in my QT5.5 application using the QCamera type of QT. A simple example of what I'm doing is
QList<QCameraInfo> cameras = QCameraInfo::avalilableCameras();
qdebug() << cameras.length();
const QCameraInfo &cameraInfo = cameras.first();
QCamera *camera = new QCamera( cameraInfo );
When I run this example, I get "No m_videoSink available!" on the command line. QT is build on Ubuntu 12.04 with libgstreamer0.10-0, libgstreamer0.10-dev and libgstreamer-plugins-base0.10-0 installed. QT is built with -qt-xcb. I have no idea what is wrong here. Does anyone have an idea?
PS: Of course I make sure that line 2 prints >= 1 ;).
Ok, finally I found the basic problem: Unfortunately Qt dropped Ubuntu 12.04 LTS support with version 5.5. With version 5.4 everything works as expected.

How to use LibVLC with Qt 5

I'm trying to use LibVLC in a Qt 5 program to open a VLC instance and play a video.
The following code comes from https://wiki.videolan.org/LibVLC_Tutorial/
I'm using Linux.
.pro :
TEMPLATE = app
TARGET = projectLoic
INCLUDEPATH += . vlc
QT += widgets
# Input
HEADERS +=
SOURCES += main.cpp
LIBS +=-lvlc
main :
#include <vlc/vlc.h>
#include <QApplication>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
libvlc_instance_t * inst;
libvlc_media_player_t *mp;
libvlc_media_t *m;
// Load the VLC engine
inst = libvlc_new(0, NULL);
// Create a new item
m = libvlc_media_new_path (inst, "/home/........mp3");
// Create a media player playing environement
mp = libvlc_media_player_new_from_media (m);
// play the media_player
libvlc_media_player_play (mp);
return app.exec();
}
The compilation is fine. But the program immediatly crashes when I build it (with Qt Creator). Any idea?
Many thanks
Many things could cause this crash. The best is to get VLC source code to trace back the issue. Passing the option '--verbose=2' when initializing libVLC can help as well.
In my case the cause of the crash was due to this bug in the ubuntu package of vlc:
https://bugs.launchpad.net/ubuntu/+source/vlc/+bug/1328466
When calling libvlc_new() vlc modules and their dependent libraries are loaded into memory. The qt module of LibVLC was searching for Qt4 shared objects instead of Qt5 (manually installed).
The solution was to rebuild the module cache which was outdated an pointing to Qt4 binaries. You can reset it on the command line:
sudo /usr/lib/vlc/vlc-cache-gen -f /usr/lib/vlc/plugins/
Or pass to vlc the option:
--reset-plugins-cache
I have never used this library, but Are you using exactly this code?
m = libvlc_media_new_path (inst, "/home/........mp3");
This path may be the problem.
What distribution of Linux are you using?
I ran into this same problem with Qt5 and LibVLC, and the primary cause (Ubuntu 12.04 LTS and 14.04 LTS), was that LibVLC was loading the qt4 interface plugin, which conflicted with Qt5. If you check your call stack, you'll most likely see that at a Qt4 library was being loaded, causing the crash.
If this is the problem, there are only 3 options (tested with LibVLC 2.2 and Qt5 on Ubuntu 12.04 and 14.04 LTS 64 bit).
The first (worst) is to delete the qt4 user interface plugin. You can test this is the problem by moving and running and then setting it back. Deleting will break your regular VLC player most likely.
Second option is to create a copy of the plugins directory and set that in your runtime path using VLC_PLUGIN_PATH, environment variable. but I've had trouble getting that to work without changing the original plugin path folder also (which will break your VLC player unless you modify your shortcuts, etc. to also set VLC_PLUGIN_PATH.
The third option, and what I ended up doing, was to custom build my own static LibVLC binary with a few edits to the source code so that it will not load the qt4 interface plugin installed with VLC. You can follow these steps to do this.
1) Download VLC Source Code for your platforms distribution.
http://download.videolan.org/pub/videolan/vlc/
Make sure you download the version matching your distribution. For
example, match the VLC version to what is installed with Ubuntu.
2) Extract source code to folder
3) Install dependencies for the OS distribution
sudo apt-get build-dep vlc
4) Modify src/modules/bank.c
Edit the module_InitDynamic function
Add the following code at the top of the function:
// HACK TO DISABLE QT4 PLUGIN
if(strstr(path, "qt4") != NULL)
return NULL;
// END HACK
3) From terminal
./bootstrap
./configure --disable-qt --disable-skins2 --enable-xcb --prefix=/home/$USER/vlc-custom_build_output_folder_name
./make
./make install
4) Copy/Save the resulting files in the install folder.
Then just link against this library instead.

QtCreator returns error "Cannot change to working directory"

I'm trying to running a simple HelloWorld program with Qt Creator
Code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
When running occurs the error
Cannot change to working directory '/home/myusername/build-myproject-Desktop-Debug': file or directory not found
Many tutorials in the internet tell me to disable "Run in terminal", but I need this for my project.
My working directory is /home/myusername/build-myproject-Desktop-Debug
Any help?
Which OS are you running?
I'm on Linux and had the same problem. My solution was to use xterm and set the default Terminal in Qtcreator to xterm (In the menu: Tools, then Options, then Environment, then Terminal, there "/usr/bin/xterm -e")
You can install Terminator terminal (sudo apt-get install terminator) and use it as Qt Creator terminal:
Tools->Options->Enviroment->System->Terminal->"/usr/bin/terminator -x"

QAudioDecoder - no service found

I am trying to decode a .wav file using QAudioDecoder class. Even though I had included the QtMultimedia module into my .pro file by adding
QT += multimedia I am receiving an error that service for the QAudioDecoder was not found. I am not able to see where to problem lies.
I am using Qt 5.1.0 with MingGW 4.8 32 bit on Windows 7.
Error message:
defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.audiodecode"
.pro file:
QT += core
QT += multimedia
QT -= gui
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
main file:
#include <QCoreApplication>
#include <QAudioDecoder>
#include <QAudioBuffer>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString pathToFile = "C:/Users/Mateusz/Documents/Szkola/Sound Processing/Lab1/artificial/easy/506Hz.wav";
QAudioDecoder decoder;
decoder.setSourceFilename(pathToFile);
decoder.start();
while(decoder.bufferAvailable()) {
QAudioBuffer buffer = decoder.read();
qDebug() << "Buffer size: " << buffer.byteCount();
}
return a.exec();
}
The Multimedia module uses plugins that are different on each platform (or compiler).
See http://qt-project.org/wiki/Qt_Multimedia_Backends
On Windows you have DirectShow and MediaFoundation (WMF).
Only the WMF plugin implements audio decoding features.
WMF plugin is only available with MSVC compiler.
See http://qt-project.org/doc/qt-5.1/qtmultimedia/platform-notes-windows.html
I had the same problem in Qt5.5 running under Linux.
The problem disappeared after upgrade to Qt5.5.1 using their MaintenanceTool.
I also struggled with this issue and finally got it to work by using the MS visual studio compiler in QT Creator, like Fernando Pelliccioni suggested.
Steps were:
-Use the Qt MaintenanceTool to add support for msvc2013
-Install Visual Studio 2013
-In Qt Creator go to Projects->Manage Kits and add msvc2013
-Build and run. Now QAudioDecoder works.

QMediaPlayer resource error

I'm using Qt Creator 2.7.2 (Qt 5.1) on Windows 8 Pro x64. I'm having trouble with QMediaPlayer. There are some MP3 files on my PC which run fine on Windows Media Player, but QMediaPlayer can't play them. Following statement:
void MainWindow::onPlayerStateChanged(QMediaPlayer::State state)
{
qDebug() << "onPlayerStateChanged" << state
<< media_player.error() << media_player.errorString();
// ....
}
is the slot connected to media player's stateChanged signal throws following output:
onPlayerStateChanged QMediaPlayer::PlayingState QMediaPlayer::NoError ""
DirectShowPlayerService::doRender: Unresolved error code 80040266
onPlayerStateChanged QMediaPlayer::StoppedState QMediaPlayer::ResourceError ""
DirectShowPlayerService::doRender: Unresolved error code 80040266
Any idea what's wrong?
It might have something to to with the ID3 tags of the file.
I had a similar problem: I was trying to play some MP3 files with QMediaPlayer. One of the files generated that error while the others played fine (on Windows 7). On Linux though, they all played fine.
So I ran the 'file' command on my MP3 files and noticed that the problematic MP3 file had a ID3 version 2.4.0 tag while all the others had ID3 version 2.3.0. I deleted the ID3 tag of that file completely using an ID3 tag editor and after that the file played successfully.
A wild guess here: DirectShow, which is used by QMediaPlayer as backend on Windows, chokes on ID3 version 2.4 and only recognizes older versions. And QMediaPlayer on Linux uses GStreamer as backend, which does not have that problem.