How to use Camera on Android and MeidiaPlayer on Windows?



  • I want to do something like this.
    @

    if on Android
    Camera {
    id: camera
    captureMode: Camera.CaptureVideo

        videoRecorder {
             resolution: Qt.size(640, 480)
             frameRate: 20
        }
        onError: {
            console.debug(errorString)
        }
    }
    

    else
    MediaPlayer {
    id: mediaplayer
    source: "D:/CI/AVA/PedestrianV2/data/subway.avi"
    }
    endif
    @



  • Hello,

    you can use Qt.platform.os to check for the operating system and bind it to the visible property of your components:
    @Camera {
    id: camera
    visible: Qt.platform.os == "android"
    captureMode: Camera.CaptureVideo
    videoRecorder {
    resolution: Qt.size(640, 480)
    frameRate: 20
    }
    onError: {
    console.debug(errorString)
    }
    }
    MediaPlayer {
    id: mediaplayer
    visible: Qt.platform.os != "android"
    source: "D:/CI/AVA/PedestrianV2/data/subway.avi"
    }@

    Otherwise you can load custom QML-Files based on the OS or a Loader which loads the Camera or the MediaPlayer dependent on the operating system:
    @Loader {
    source: Qt.platform.os == "android" ? camera : mediaplayer
    }@

    For further information please read:
    "Platform Property":http://doc-snapshot.qt-project.org/qt5-release/qtqml/qml-qtqml2-qt.html#platform-prop
    "Loader":http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-loader.html


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.