Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom URL protocol handler Qt 5

I want to use a Video/MediaPlayer QML element in my app, and have it play a video from a custom stream. QMediaPlayer seems to support this since you can tell it to read from a QIODevice which can do anything you want. But MediaPlayer only supports a URL.

Is there any way I can register my own URL scheme that uses my own streaming protocol? For example, say I wanted to make rtsp2://..., could I do something vaguely like:

class Rtsp2 : public QIODevice
{
    // open, read, seek, close, etc.
}

QCoreApplication::registerUrlProtocol("rtsp2", Rtsp2);
like image 308
Timmmm Avatar asked Dec 24 '12 20:12

Timmmm


1 Answers

I haven't looked at the details, but the QML engine has a QNetworkAccessManager it uses for connectivity. You can add your own protocols at the QNAM layer by subclassing and hooking createRequest. However I suspect QMediaPlayer might not uses this QNAM for media loading, because the underlying media layer often provides its own IO abstraction.

(Also, adding custom protocols to QNAM isn't exactly trivial - ideally it would be a simple 'registerProtocolFor' call but sadly this is not the case)

like image 52
James Turner Avatar answered Sep 19 '22 23:09

James Turner