Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/videomonitorwidget.cpp
Show All 19 Lines | |||||
20 | #include <QDir> | 20 | #include <QDir> | ||
21 | #include <QGridLayout> | 21 | #include <QGridLayout> | ||
22 | #include <QPushButton> | 22 | #include <QPushButton> | ||
23 | #include <QVideoWidget> | 23 | #include <QVideoWidget> | ||
24 | #include "videomonitorwidget.h" | 24 | #include "videomonitorwidget.h" | ||
25 | 25 | | |||
26 | VideoMonitorWidget::VideoMonitorWidget(QWidget *parent) : | 26 | VideoMonitorWidget::VideoMonitorWidget(QWidget *parent) : | ||
27 | QWidget(parent) | 27 | QWidget(parent) | ||
28 | , _mediaplayer(nullptr, QMediaPlayer::StreamPlayback) | 28 | , _errorlabel(new QLabel(this)) | ||
29 | , _mediaplayer(this, QMediaPlayer::StreamPlayback) | ||||
29 | { | 30 | { | ||
30 | auto _layout = new QGridLayout(); | 31 | auto _layout = new QGridLayout(); | ||
31 | auto _label = new QLabel(i18n("Source url:")); | 32 | auto _label = new QLabel(i18n("Source url:"), this); | ||
32 | _layout->addWidget(_label, 0, 0); | 33 | _layout->addWidget(_label, 0, 0); | ||
33 | 34 | | |||
34 | auto _sourceCB = new QComboBox(); | 35 | auto _sourceCB = new QComboBox(this); | ||
35 | _sourceCB->setEditable(true); | 36 | _sourceCB->setEditable(true); | ||
36 | _sourceCB->setToolTip(i18n("Valid Urls:\n\ | 37 | _sourceCB->setToolTip(i18n("Valid Urls:\n\ | ||
37 | http://www.example.com/stream.avi\n\ | 38 | http://www.example.com/stream.avi\n\ | ||
38 | rtp://@:1234\n\ | 39 | rtp://@:1234\n\ | ||
39 | mms://mms.examples.com/stream.asx\n\ | 40 | mms://mms.examples.com/stream.asx\n\ | ||
40 | rtsp://server.example.org:8080/test.sdp")); | 41 | rtsp://server.example.org:8080/test.sdp")); | ||
41 | _layout->addWidget(_sourceCB, 0, 1); | 42 | _layout->addWidget(_sourceCB, 0, 1); | ||
42 | 43 | | |||
43 | auto _playPB = new QPushButton(); | 44 | auto _playPB = new QPushButton(this); | ||
44 | _playPB->setCheckable(true); | 45 | _playPB->setCheckable(true); | ||
45 | _playPB->setIcon(QIcon::fromTheme("media-playback-start", style()->standardIcon(QStyle::SP_MediaPlay))); | 46 | _playPB->setIcon(QIcon::fromTheme("media-playback-start", style()->standardIcon(QStyle::SP_MediaPlay))); | ||
46 | _layout->addWidget(_playPB, 0, 2); | 47 | _layout->addWidget(_playPB, 0, 2); | ||
47 | 48 | | |||
48 | auto _videoWidget = new QVideoWidget(); | 49 | auto _videoWidget = new QVideoWidget(this); | ||
49 | _layout->addWidget(_videoWidget, 1, 0, -1, -1); | 50 | _layout->addWidget(_videoWidget, 1, 0, -1, -1); | ||
50 | 51 | | |||
51 | _errorlabel = new QLabel; | | |||
52 | _layout->addWidget(_errorlabel, 2, 0, 0, -1); | 52 | _layout->addWidget(_errorlabel, 2, 0, 0, -1); | ||
53 | 53 | | |||
54 | this->setLayout(_layout); | 54 | this->setLayout(_layout); | ||
55 | 55 | | |||
56 | _mediaplayer.setVideoOutput(_videoWidget); | 56 | _mediaplayer.setVideoOutput(_videoWidget); | ||
57 | 57 | | |||
58 | #ifdef Q_OS_LINUX | 58 | #ifdef Q_OS_LINUX | ||
59 | QStringList sources; | 59 | QStringList sources; | ||
Show All 12 Lines | 67 | if (b) { | |||
72 | _playPB->setIcon(QIcon::fromTheme("media-playback-pause", style()->standardIcon(QStyle::SP_MediaPause))); | 72 | _playPB->setIcon(QIcon::fromTheme("media-playback-pause", style()->standardIcon(QStyle::SP_MediaPause))); | ||
73 | _mediaplayer.play(); | 73 | _mediaplayer.play(); | ||
74 | } else { | 74 | } else { | ||
75 | _mediaplayer.pause(); | 75 | _mediaplayer.pause(); | ||
76 | _playPB->setIcon(QIcon::fromTheme("media-playback-start", style()->standardIcon(QStyle::SP_MediaPlay))); | 76 | _playPB->setIcon(QIcon::fromTheme("media-playback-start", style()->standardIcon(QStyle::SP_MediaPlay))); | ||
77 | } | 77 | } | ||
78 | _videoWidget->setVisible(b); | 78 | _videoWidget->setVisible(b); | ||
79 | }); | 79 | }); | ||
80 | 80 | using ErrorSignal = void (QMediaPlayer::*)(QMediaPlayer::Error); | |||
81 | typedef void (QMediaPlayer::*ErrorSignal)(QMediaPlayer::Error); | | |||
82 | connect(&_mediaplayer, static_cast<ErrorSignal>(&QMediaPlayer::error), | 81 | connect(&_mediaplayer, static_cast<ErrorSignal>(&QMediaPlayer::error), | ||
83 | this, &VideoMonitorWidget::handleError); | 82 | this, &VideoMonitorWidget::handleError); | ||
84 | } | 83 | } | ||
85 | 84 | | |||
86 | void VideoMonitorWidget::handleError() | 85 | void VideoMonitorWidget::handleError() | ||
87 | { | 86 | { | ||
88 | const QString errorString = _mediaplayer.errorString(); | 87 | const QString errorString = _mediaplayer.errorString(); | ||
89 | QString message = "Error: "; | 88 | QString message = "Error: "; | ||
90 | if (errorString.isEmpty()) { | 89 | if (errorString.isEmpty()) { | ||
91 | message += " #" + QString::number(int(_mediaplayer.error())); | 90 | message += " #" + QString::number(int(_mediaplayer.error())); | ||
92 | } else { | 91 | } else { | ||
93 | message += errorString; | 92 | message += errorString; | ||
94 | } | 93 | } | ||
95 | _errorlabel->setText(message); | 94 | _errorlabel->setText(message); | ||
96 | } | 95 | } |