How to play video files in qt - c++

I want to play video file in qt. But when i am using QMediaPlayer Class, it is throwing an error as : fatal error: No such file or directory.
QMediaPlayer *player = new QMediaPlayer;
QMediaPlaylist *playlist = new QMediaPlaylist(player);
playlist->addMedia(QUrl("http://example.com/myclip1.mp4"));
playlist->addMedia(QUrl("http://example.com/myclip2.mp4"));
QVideoWidget *videoWidget = new QVideoWidget;
player->setVideoOutput(videoWidget);
videoWidget->show();
playlist->setCurrentIndex(1);
player->play();
When i am including QMediaPlayer class it is throwing error.
I am using Qt4.8.4 Version, Ubuntu 12.04 in my system

Are you sure that QMediaPlayer is a feature in 4.8.4?
http://qt-project.org/doc/qt-5/qmediaplayer.html
It looks like it has been introduced with Qt5.
Check out this example for 4.8.4 video playback:
http://qt-project.org/doc/qt-4.8/demos-qmediaplayer.html

Add to the .pro file:
CONFIG += mobility
MOBILITY += multimedia

Check the videoplayer from here, I didn't try it, but it might help you: http://radekp.github.io/qtmoko/api/phonon-videoplayer.html:

Related

Invisible text in QTextEdit

I am learning Qt and running examples from Qt SDK 5.9.1. I run the code below and write inside QTextEdit but no text appears. Cursor moves as I write but no text is shown. Window title text is shown. I added addApplicationFont and setFont calls below I found from web to the sample but it didn't help.
#include <QtWidgets>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QFontDatabase::addApplicationFont("://Ubuntu-R.ttf");
app.setFont(QFont("Ubuntu", 11, QFont::Normal, false));
QTextEdit textEdit;
textEdit.show();
return app.exec();
}
I am on Ubuntu 16.04 and run following commands on bash to make executable:
qmake -makefile
make
./part1
I want the app to use the default Ubuntu system font. I learned that Qt uses fontconfig for fonts but I don't know how to trace the issue.
Edit
I thought QFontDatabase::addApplicationFont("://Ubuntu-R.ttf") call referenced system font but instead it is referencing font app resource file. I don't have resource file so obviously it won't work.
.pro file is below(unmodified sample file):
QT += widgets
SOURCES = main.cpp
# install
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tutorials/gettingStarted/gsQt/part1
INSTALLS += target
I tried to get system font using QFontDatabase but it didn't work:
app.setFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont));
This doesn't do anything with any of enum values including QFontDatabase::GeneralFont
QFontDatabase database;
QStringList fam = database.families();
fam size is zero.
I will try to use embedded font next.
I don't know the exact reason of the problem but the reason was not configuring fontconfig dependency properly before building qt. I solved it by reconfiguring and recompiling qt again. You can find more details at qt forum.

Playing *.avi files with Qt

I am trying to play *.avi file (~900MB) with this code:
QMediaPlayer* player = new QMediaPlayer(this);
player->setMedia(QUrl::fromLocalFile("mes1.avi"));
player->setVideoOutput(ui->videoWidget);
player->play();
where ui->videoWidget is QVideoWidget and every time I play it I am getting this error code (in Application Output console)
Since google doesn't help, this is my only choice...
DirectShowPlayerService::doRender: Unresolved error code 0x80040266 (IDispatch error #102)
EDIT1:
I have installed K-Lite Codec Pack 12.2.6.
EDIT2:
My application is 32bit, but it shouldn't be a problem since K-Lite include 32bit (source).
Use vlc-qt, and you will find it is so easy to play all sorts of video on all platforms, even XP, which has been abandoned by qt long time ago.

Why are my qt file dialogs rendered incorrectly?

I'm currently creating a GUI with Qt 5.6 and I want to let the user open a file. I do this using the following code in my main window class:
#include <QFileDialog>
...
void MainWindow::loadScene()
{
QString loadPath = QFileDialog::getOpenFileName(this,
tr("Choose a scene file"), QString("."),
tr("Scene files (*.keyScene)"));
if(!loadPath.isEmpty())
resourceManager->loadScene(loadPath.toStdString());
}
I get the following dialog:
Screenshot of open file dialog
The system I use is Ubuntu 16.04, I've also tested on Ubuntu 14.04 and Mint 17.3. I get the exact same result on all of them.
When I compile the project in Windows everything works fine.
EDIT
It was suggested I play around with the DontUseNativeDialog flag when creating a file dialog, I can get a working Qt style file dialog with the following code:
QFileDialog dialog(this);
dialog.setAcceptMode(QFileDialog::AcceptOpen);
dialog.setOption(QFileDialog::Option::DontUseNativeDialog, true);
if(!dialog.exec())
return;
So the question is actually why native file dialogs aren't rendered correctly.

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.

qt 5 QMediaPlayer error: Gstreamer unable to play

I just installed QT 5 and am trying to run the example for playing video. The code snippet looks like:
QMediaPlayer *player = new QMediaPlayer;
player->setMedia( QUrl::fromLocalFile(fileUrl) );
QVideoWidget *videoWidget = new QVideoWidget;
player->setVideoOutput(videoWidget);
videoWidget->show();
player->play();
It compiles fine, but when I run it I get the following error:
GStreamer; Unable to play - "file:sample.avi"
Im on Ubuntu 12.04 and have installed all of the extra gstreamer packages in case gstreamer was missing codecs. Ive tried with a few different video formats to no avail. I can play the videos using vlc just fine. Does anyone have any idea why this isnt working?
It needs absolute path. Try
player->setMedia( QUrl::fromLocalFile(QFileInfo(fileUrl).absoluteFilePath()));