11
I’m trying to use the classes QMediaPlayer
and QVideoWidget
to display a video on a system I’m producing. Only these class rays don’t work as expected. The QVideoWidget
just doesn’t show up, doesn’t show the video, doesn’t do anything!
THE MCVE
To illustrate the problem, I built a Minimum, Complete and Verifiable Example on the basis of in the Qt 5 documentation example itself. Below are the configuration files of Cmake (for setting up the environment - i.e., creating the Visual Studio or Makefile project) and code:
Cmakelists.txt:
cmake_minimum_required(VERSION 2.8.11)
project (Teste)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
# Configuração do Qt
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Multimedia REQUIRED)
find_package(Qt5MultimediaWidgets REQUIRED)
# Cria o executável
if(WIN32)
add_executable(Teste WIN32 main.cpp)
else()
add_executable(Teste main.cpp)
endif()
# Adiciona as bibliotecas necessárias
target_link_libraries(Teste Qt5::Widgets Qt5::Multimedia Qt5::MultimediaWidgets)
main.cpp:
#include <QApplication>
#include <QMediaPlayer>
#include <QVideoWidget>
#include <QMediaPlaylist>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QMediaPlayer *player;
QMediaPlaylist *playlist;
QVideoWidget *videoWidget;
// Código tirado do exemplo em: http://doc.qt.io/qt-5/qvideowidget.html#details
// -------------------------
player = new QMediaPlayer;
playlist = new QMediaPlaylist(player);
playlist->addMedia(QUrl("http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4"));
playlist->addMedia(QUrl("http://techslides.com/demos/sample-videos/small.mp4"));
videoWidget = new QVideoWidget;
player->setVideoOutput(videoWidget);
videoWidget->show();
playlist->setCurrentIndex(1);
player->play();
// -------------------------
return app.exec();
}
The Problem
When I run the code, the component (QVideoWidget
) apparently not "is created" (despite being shown, since to ensure that the problem is not another I call show
directly on the bastard), because the window appears "shortened" (without any standard size):
But even if I use the mouse to resize the window, there is nothing displayed:
The code does not generate any exceptions or errors. In the minimum example I use video Urls just to facilitate the tests (and as it is in the documentation), but on my local system I read local files and the problem is exactly the same.
The Environment
My development environment is:
- Windows 10 64 bits
- Cmake 3.5.0-rc3
- Qt 5.6.0 32 bits
- Visual Studio 2015
EDIT
I just tested on Ubuntu (16.04 64 bits) with Qt 5.7 (64 bits) and the problem is exactly the same:
I found a little strange your test with external urls, maybe it is necessary to download first, because the player does not pass the data pro encoder if the download does not finish, maybe it recognizes fractions of the file, but it may still be necessary to create a temporary Handler. Tell me, tried with local files?
– Guilherme Nascimento
Ah, even your questions come here to "humiliate" people who can’t post anything right :D Pity I can’t help ;)
– Maniero
@Guilhermenascimento In my code I use local files, and it doesn’t work either. I only used external Urls because it makes it easier to build [mcve]. Anyway, it should work equally (and as the example of the documentation). :)
– Luiz Vieira
@bigown Opa, sorry ai. rs :)
– Luiz Vieira
Just ask me a question, prompted the necessary codecs? If running in DEBUG mode appear errors of attempts to use the codecs.
– Guilherme Nascimento
@Guilhermenascimento I believe so. Because my machine runs the videos (the places I try to run are .mp4) on VLC without problems for example. In addition, I have already run in DEBUG and no error has appeared. But, now you take me a doubt: the minimum example I did runs normally there for you?
– Luiz Vieira