Soukaina Ouad
Soukaina Ouad

Reputation: 71

Unable to play video in QML

I am working on ubuntu 14.04 with Qt 5.8 and trying to play video in my application using Qt multimedia module. I put "QT += quick multimedia" in ".pro".

ContentVideo.qml

import QtQuick 2.1
import QtMultimedia 5.0

Rectangle {
    width: 400
    height: 400
    color:"black"

    MediaPlayer {
        id: mediaPlayer
        autoPlay: true
        autoLoad: true
        source:"/home/macos/Desktop/FroggerHighway.mp4"
    }

    VideoOutput {
        id:videoOutput
        source:mediaPlayer
        anchors.fill: parent
    }
}

main.qml

import QtQuick 2.1
import QtQuick.Window 2.1

Window {
    id: root
    color: "black"
    width: 400
    height: 400
    visible: true
    ContentVideo {
        anchors.fill: parent
    }
}

My video is not running and I am getting black screen without any error. QT QML EXAMPLES video is working on my PC. Any help will appreciated, Thank you.

Upvotes: 7

Views: 10954

Answers (6)

clrs
clrs

Reputation: 39

Since qt6 prefers cmake instead of qmake so in case you want to add multimedia files to your cmake list you could perfrom the steps given below (the solution below worked on a mac (apple silicon))

  1. First download the multimedia package from the qt maintenance tool (QtMultimedia) enter image description here
  1. Add it to the cmake project list by including the following lines

     find_package(Qt6 6.2 COMPONENTS Multimedia REQUIRED)
    
  2. Also update the target_link_libraries

     target_link_libraries(yourprojectname, PRIVATE Qt6::Multimedia)
    
  3. Also set autorcc on

     set(CMAKE_AUTORCC ON)
    
  4. Save your cmake file

  5. Regarding the qml file the following code worked for me without errors

     import QtQuick
     import QtQuick.Controls
     import QtMultimedia
    
     ApplicationWindow
     {
         width:640
         height: 480
         visible : true
         title: "audio player"
         MediaPlayer {
             id: player 
             source : "give your path to source file "
             audioOutput: AudioOutput{}
    
         Component.onCompleted:{
             player.play();
         }
        }
       }
    

Upvotes: 0

Manuel Schmitzberger
Manuel Schmitzberger

Reputation: 5468

I faced the same problem on Arch and Debian. After installing the following packages, everything works fine.

ARCH:

  • extra/gstreamer
  • aur/gstreamer0.10
  • extra/gst-plugins-base-libs
  • extra/gst-plugins-good
  • extra/gst-libav
  • extra/qt5-tools

Installed with yay:

yay -S gstreamer gstreamer0.10 gst-plugins-base-libs gst-plugins-good gst-libav qt5-tools

Debian:

  • libqt5multimedia5-plugins
  • gstreamer1.0-plugins-good
  • gstreamer1.0-libav
  • libqt5multimediagsttools5

Installed with apt:

apt install libqt5multimedia5-plugins 

Upvotes: 1

Vineesh TP
Vineesh TP

Reputation: 7963

Add QT+= multimedia to your .pro file.

Upvotes: 1

id9502
id9502

Reputation: 31

I had just met the same issue as yours, it seems that QtMultimedia will looking for decoders from gstreamer in system at run time, so I install video codec package:

sudo apt-get install gstreamer1.0-libav gstreamer1.0-vaapi

Then qml video player works correctly now

Upvotes: 3

Takeshi Kanemoto
Takeshi Kanemoto

Reputation: 51

MediaPlayer.source is a URI and I don't think the value you are specifying is a valid URI. Try adding "file://" in front of the path the the mp4 file.

Upvotes: 5

rbaleksandar
rbaleksandar

Reputation: 9681

If the QML video examples work without any issues it's probably a problem that comes from the lack of codecs to encode your video. Check if you have all the Multimedia Dependencies. My guess is that the provided video samples are encoded in a open format the support for which is provided by default by your distro.

Upvotes: 1

Related Questions