Question

I am looking for a best way to implement a video player application in QML. Almost all QML examples are reading files from filesystem or web:

MediaPlayer {
    id: mediaplayer
    source: "groovy_video.mp4"
}

VideoOutput {
    anchors: parent.fill
    source: mediaplayer
}

I want to specify my own source for MediaPlayer - a C++ QObject derived class, that has an interface similar to QIODevice. That would be perfect for my needs. I need to preload video in parts and also to cache it for later use.

Is there an easy solution for my needs? (I am using Qt 5.2)

Était-ce utile?

La solution

Generally speaking you should be able to override any URL that is loaded by QML. The Qt 4 docs are a bit more explicit about this than Qt 5:

https://doc.qt.io/qt-4.8/qdeclarativenetwork.html

But the same should be similar for Qt 5:

http://doc.qt.io/qt-5/qqmlnetworkaccessmanagerfactory.html

e.g. you should be able to use a specific url schema for a custom source magic+videos://.... for your custom source.

Worst case scenario you have to inherit (and override some methods) from QNetworkAccessManager and QNetworkReply (which inherits from QIODevice).

I have not played with this since qt4 but I assume a good starting point would be this:

http://doc.qt.io/qt-5/qtqml-networkaccessmanagerfactory-example.html

I'm a bit outdated on this kind of stuff, but hopefully this helps.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top