I have Qt5 built with submodule QtMultimedia on Debian Jessie 8.2 (BeagleBone Black), I use GStreamer backend (version 0.10.36). I tried to use this simple example to play a video, but it gives me error when trying to play .AVI file: Internal data flow error.
Is the problem in video plugins/codecs I have?
Here is the code:
#include "mainwindow.h"
#include <QApplication>
#include <QMediaPlayer>
#include <QVideoWidget>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMediaPlayer *player = new QMediaPlayer;
QVideoWidget *vw = new QVideoWidget;
player->setVideoOutput(vw);
player->setMedia(QUrl::fromLocalFile("/home/debian/video.avi"));
vw->setGeometry(100, 100, 320, 240);
vw->show();
player->play();
return a.exec();
}
Related
I am trying to make the QtVirtualKeyboard example work with QQuickWidget instead of QQuickView. For QuickView, I use the following main.cpp code, which works fine for me:
#include <QQuickView>
#include <QGuiApplication>
#include <QQmlEngine>
int main(int argc, char *argv[])
{
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
QGuiApplication app(argc, argv);
QQuickView view(QString("qrc:/%2").arg(MAIN_QML));
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.show();
return app.exec();
}
I run into problems, when changing to QQuickWidgets with the following implementation of main.cpp:
#include <QQuickWidget>
#include <QApplication>
#include <QQmlEngine>
int main(int argc, char *argv[])
{
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
QApplication app(argc, argv);
QQuickWidget w(QString("qrc:/%2").arg(MAIN_QML));
w.setResizeMode(QQuickWidget::SizeRootObjectToView);
w.show();
return app.exec();
}
When I hit the input fields, the virtual keyboard shows up, but when I start typing at the keyboard, I get the message "input method is not set", which seems to be related to the input method plugin. No chars appear in the input fields.
Any ideas? The QML-code didn't change between the above variants of main.cpp
BTW: I am using Linux, gcc, Qt 5.9.0, EGLFS plugin
Thanks for any suggestions!
Regards,
Patrick
Found the solution for QML looking through inputMethod documentation. Following workaround works for me:
TextArea {
...
onActiveFocusChanged: {
if(activeFocus) {
Qt.inputMethod.update(Qt.ImQueryInput)
}
}
}
Works with other controls as well.
Of course InputPanel should be defined in ApplicationWindow like this:
ApplicationWindow {
...
InputPanel {
id: inputPanel
...
}
}
Here is the code
#include <QApplication>
#include <QtWebKitWidgets/QWebView>
int main(int argc, char * argv[])
{
QApplication app(argc, argv);
QWebView view;
QCoreApplication::addLibraryPath("./plugins");
view.settings()->setAttribute(QWebSettings::PluginsEnabled, true);
// crash here
view.load(QUrl("http://hon.qq.com/act/20140320video/Aluna.html"));
// OK to show youtube
//view.load(QUrl("http://www.youtube.com/watch?v=KMU0tzLwhbE"));
view.show();
return app.exec();
}
It crashes when play video on hon.qq.com, but works well playing video on Youtube.
Given below is the code for playing a video file using Qt. Instead of playing the video I want to play a live video stream from an IP Camera. Another approach is to embed the VLC Player in Qt and a link for the project is provided here. The problem is I do not know how to include the player in Qt. So how do I proceed?
#include <QApplication>
#include <QtMultimediaWidgets/QVideoWidget>
#include <QtMultimedia/QMediaPlayer>
#include <QtMultimedia/QMediaPlaylist>
#include <QFile>
#include <QHBoxLayout>
#include "DemoPlayer.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget *widget=new QWidget;
widget->resize(400,300);
QMediaPlayer *player=new QMediaPlayer;
QVideoWidget *vw= new QVideoWidget;
QHBoxLayout *layout=new QHBoxLayout;
layout->addWidget(vw);
widget->setLayout(layout);
player->setVideoOutput(vw);
player->setMedia(QUrl::fromLocalFile("C:/Users/Administrator/Desktop/1minute.mp4"));
player->play();
widget->show();
qDebug()<<player->availableMetaData()<<player->currentMedia().canonicalUrl();
return a.exec();
}
follow this code . you can embed a widget inside another widget using a valid window id .
How to show output video of other application in Qt?
you can use the qx11embedwidget and qx11embedwidgetcontainer
QX11EmbedWidget and QX11EmbedContainer
Given below is the code for playing a video. On running it, it says that it could not open file.
#include <QApplication>
#include <QtMultimediaWidgets/QVideoWidget>
#include <QtMultimedia/QMediaPlayer>
#include <QtMultimedia/QMediaPlaylist>
#include <QFile>
#include <QHBoxLayout>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget *widget=new QWidget;
widget->resize(400,300);
QMediaPlayer *player=new QMediaPlayer;
QVideoWidget *vw= new QVideoWidget;
QHBoxLayout *layout=new QHBoxLayout;
layout->addWidget(vw);
widget->setLayout(layout);
player->setVideoOutput(vw);
QFile file=("1minute.mp4");
if(!file.open(QIODevice::ReadOnly))
qDebug()<<"Could not open file";
player->setMedia(QUrl::fromLocalFile("1minute.mp4"));
player->play();
widget->show();
qDebug()<<player->availableMetaData()<<player->currentMedia().canonicalUrl();
return a.exec();
}
Where am I going wrong?
Finally found the answer. Added the complete link of the video and it started playing easily.
SO the code for the video link should be:
player->setMedia(QUrl::fromLocalFile("C:/Users/Administrator/Desktop/1minute.mp4"));
How to create QML such canvas, and attach XOverlay video object on that canvas?
Java:
final Canvas canvas = new Canvas();
canvas.setPreferredSize(new Dimension(200, 200));
XOverlay.wrap(video).setWindowID(canvas);
C++
#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QmlApplicationViewer viewer;
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
viewer.setMainQmlFile(QLatin1String("qml/QmlTest1/main.qml"));
// set the window no border, to do full screen live VIDEO
viewer.setWindowFlags(
Qt::CustomizeWindowHint |
Qt::FramelessWindowHint
);
viewer.showExpanded();
return app.exec();
}
My ref:
http://doc.qt.nokia.com/4.7-snapshot/qdeclarativeexamples.html
http://www.scriptol.com/programming/qml.php
Video playback in QML can be done through Qt Mobility's Video element:
http://doc.qt.nokia.com/qtmobility-1.2/qml-video.html