Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to use Camera on Android and MeidiaPlayer on Windows?
Qt 6.12 LTS is out! See what's new in the release blog

How to use Camera on Android and MeidiaPlayer on Windows?

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 1.7k Views 1 Watching
  • 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.
  • L Offline
    L Offline
    lygstate
    wrote on last edited by
    #1

    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
    @

    1 Reply Last reply
    0
    • O Offline
      O Offline
      onek24
      wrote on last edited by
      #2

      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

      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
      • Unsolved