Play custom stream using QMediaPlayer

I searched carefully to find the answer to my problem, but no other post has been helpful so far. I am developing an application in Qt where I need to play a video stream that is received through a user protocol. I found myself trying to feed these packages in QMediaPlayer in every way without success. My idea was to write incoming packages in QBuffer and then read them from QMediaPlayer. Follow my test:

/// VideoPlayer.h
class VideoPlayer : public QWidget
{
public slots:
    void play();
    void handlePacket(QByteArray);
    [...]

private:
    QMediaPlayer mediaPlayer;
    QBuffer      buffer;
};

/// VideoPlayer.cpp
VideoPlayer::VideoPlayer(QWidget *parent)
: QWidget(parent)
, mediaPlayer(0, (QMediaPlayer::StreamPlayback))
{
    buffer.open(QBuffer::ReadWrite);
}

void VideoPlayer::handlePacket(QByteArray packet)
{
    buffer.buffer().append(packet);
}

void VideoPlayer::play()
{
    mediaPlayer.setMedia(QMediaContent(), &buffer);
    mediaPlayer.play();
}

QMediaPlayer mediaPlayer.setMedia(QMediaContent(), &buffer), , , , . , , QByteArray ( , QIODevice:: readyRead , )? QMediaPlayer , setMedia. QMediaPlayer , ?

? QIODevice - Qt, QMediaContent?

- , ?

Qt 5.4. .

+4
3

- , . .

. , [ ] . :

  • RGB , (lol nevermind)

Main: Qt-. , libVLC [ ], /, . , , .

-:

// init method
{
    // ...
    mPlayer = new QMediaPlayer(this, QMediaPlayer::StreamPlayback);
    mBuffer = new QBuffer(this);
    mBuffer->open(QIODevice::ReadWrite);
    // ...
}

// trying to play audio portion
void MyCoolPlayer::handleFrameAudio(const QByteArray &audioBlob)
{
    mBuffer->seek(0);
    mBuffer->write(audioBlob);
    mBuffer->seek(0);
    mPlayer->setMedia(QMediaContent(), mBuffer);
    mPlayer->play();
}

, - .

, /, :

  • QPainter:: drawImage rgb
  • QAudioOutput pcm.
+1
0

POC QT/QML. QBuffer. . QMediaPlayer . , .

,

  1. QML VideoOutput QMediaPlayer C++, setMedia(QUrl("http://127.0.0.1:8080"));. VLC HTTP 8080.

  2. , VLC, , QMediaPlayer setMedia(QMediaContent(), &localFile);.

0

All Articles