Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML MediaPlayer with timer to reconnect streaming

QML MediaPlayer with timer to reconnect streaming

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 300 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    iodev
    wrote on last edited by iodev
    #1

    Good morning,

    I programmed a QML MediaPlayer streaming an IP camera. I coded a timer to reconnect if the video signal is lost. I tried this on Linux and it works perfectly when I disconnect the camera it emits the signal "OnError" but when I try this on Windows (with 5.15.2 MinGW 64 bit) the code doesn't emit the signal "OnError" after disconnecting the camera and I don't know the reason. If anyone has any idea about what could be the difference between Windows and Linux about this code I would be very grateful. Thanks in advance.

    import QtQuick 2.7
    import QtMultimedia 5.5
    import QtQuick.Controls 2.0
    import QtQuick.Controls.Styles 1.4
    
    Rectangle {
        property alias source: mediaPlayer.source
        property alias volume: mediaPlayer.volume
        property alias title: videoTitle.text
        property bool inverted: false
        property alias fadeOverlay: fade
        property alias player: mediaPlayer
        property alias color: background.color
    
        width: 640
        height: 360
    
        // Reconnection timer
           Timer {
               id: timer
           }
           function delay( delayTime, callback ) {
               timer.interval = delayTime;
               timer.repeat = false;
               timer.triggered.connect( callback );
               timer.start( );
           }
    
           MediaPlayer {
               id: mediaPlayer
               autoPlay: true
               autoLoad: false
               loops: MediaPlayer.Infinite
               volume: usv.sound
               onPlaying: {
                   busyIndicator.running = false
               }
               onError: {
                   busyIndicator.running = true;
                   console.log( "Error" );
    
    
                   // Retry connection
                   delay( 5000, function( ) {
                       mediaPlayer.play( );
                   } );
               }
           }
    
        // Info overlay
        PropertyAnimation {
            id: fade
            //target: overlay
            target: overlay
            properties: "opacity"
            to: 1 - overlay.opacity
            duration: 200
        }
    
        Rectangle {
            id: overlay
            color: "transparent"
            anchors.fill: parent
            border.color: "#00000000"
            opacity: 1
            z: 2
    
            Text {
                id: videoTitle
                x: 5
                y: 5
                color: "#e4ff04"
                text: qsTr("Title")
                z: 1
                style: Text.Outline
                font.pixelSize: 14
                styleColor: "#000000"
            }
    
    
        }
    
        // Video output
        VideoOutput {
            id: videoOutput
            anchors.fill: parent
            source: mediaPlayer
            Rectangle {
                anchors.fill: parent
                id: background
                color: "#000000"
                border.color: "#00000000"
                z: -1
            }
            transform: Scale {
                yScale: inverted ? ( -1 ) : 1
                origin.x: width / 2
                origin.y: height / 2
            }
        }
    
        BusyIndicator {
            id: busyIndicator
            anchors.verticalCenter: parent.verticalCenter
            anchors.horizontalCenter: parent.horizontalCenter
        }
    
    }
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved