title: How do i play a stream with QMediaPlayer
body: <p>I have set up a server and video streaming so that I can connect to the stream with ffplay using the following command line:</p>
  
  <pre><code>ffplay rtmp://&lt;IP&gt;/path
  </code></pre>
  
  <p>Is it possible to use QMediaPlayer QMediaContent or something to connect to this stream?</p>
  
  <p>Or maybe any other kind of stream I can create with ffserver.</p>
  
  <p>using the same path as with ffplay results in "Unsupported url scheme!"</p>
  
  <p>With further experiments i have tried ffserver http server streaming, but that ended with Qt crashing in MFStreamer::doRead()</p>
  
  <p>Apparently it should have called BeginRead for MFStreamer but it didn't.</p>
  
  <p>How do i play video streams with QMediaPlayer?</p>
  
  <p>Edit: here's my code</p>
  
  <p><strong>videotest.cpp</strong></p>
  
  <pre><code>#include "videotest.h"
  #include &lt;QVBoxLayout&gt;
  #include &lt;QVideoWidget&gt;
  #include &lt;qmediaplayer.h&gt;
  #include &lt;QMediaContent&gt;
  #include &lt;QNetworkAccessManager&gt;
  #include &lt;QNetworkReply&gt;
  
  struct VideoTest::Private
  {
      QMediaPlayer * mediaPlayer;
      QNetworkAccessManager * networkAccessManager;
      QNetworkReply * reply;
  };
  
  VideoTest::VideoTest(QWidget *parent)
      : QMainWindow(parent)
  {
      d = new Private;
      d-&gt;mediaPlayer = new QMediaPlayer(this, QMediaPlayer::StreamPlayback);
      d-&gt;networkAccessManager = new QNetworkAccessManager(this);
      ui.setupUi(this);
  
      QVideoWidget * videoWidget = new QVideoWidget(ui.centralWidget);
      videoWidget-&gt;show();
      QPalette palette = videoWidget-&gt;palette();
      palette.setColor(QPalette::Background, QColor(0, 0, 0));
      videoWidget-&gt;setPalette(palette);
  
      ui.videoLayout-&gt;addWidget(videoWidget);
      d-&gt;mediaPlayer-&gt;setVideoOutput(videoWidget);
  
      connect(ui.playButton, SIGNAL(clicked()), d-&gt;mediaPlayer, SLOT(play()));
      connect(ui.pauseButton, SIGNAL(clicked()), d-&gt;mediaPlayer, SLOT(pause()));
      connect(ui.videoUrlEdit, SIGNAL(editingFinished()), this, SLOT(sourceChanged()));
      connect(d-&gt;mediaPlayer, SIGNAL(error()), this, SLOT(stateChanged()));
      connect(d-&gt;mediaPlayer, SIGNAL(stateChanged), this, SLOT(stateChanged()));
  }
  
  VideoTest::~VideoTest()
  {
      delete d;
  }
  
  void VideoTest::sourceChanged()
  {
      d-&gt;reply = d-&gt;networkAccessManager-&gt;get(QNetworkRequest(ui.videoUrlEdit-&gt;text()));
      if(d-&gt;reply)
      {
          connect(d-&gt;reply, SIGNAL(readyRead()), this, SLOT(networkRequestReady()));
      }
  }
  
  void VideoTest::stateChanged()
  {
      QString text = ui.textEdit-&gt;toPlainText();
      text.append("\n").append(d-&gt;mediaPlayer-&gt;errorString()).append(" : ").append(d-&gt;mediaPlayer-&gt;mediaStatus());
      ui.textEdit-&gt;setText(text);
  }
  
  void VideoTest::networkRequestReady()
  {
      d-&gt;mediaPlayer-&gt;setMedia(QMediaContent(), d-&gt;reply);
  }
  </code></pre>
  
  <p><strong>videotest.h</strong></p>
  
  <pre><code>#ifndef VIDEOTEST_H
  #define VIDEOTEST_H
  
  #include &lt;QtWidgets/QMainWindow&gt;
  #include "ui_videotest.h"
  
  class VideoTest : public QMainWindow
  {
      Q_OBJECT
  
  public:
      VideoTest(QWidget *parent = 0);
      ~VideoTest();
  
  public slots:
      void sourceChanged();
      void stateChanged();
      void networkRequestReady();
  
  private:
      Ui::VideoTestClass ui;
      struct Private;
      Private * d;
  };
  
  #endif // VIDEOTEST_H
  </code></pre>