Changeset View
Changeset View
Standalone View
Standalone View
src/panels/information/phononwidget.cpp
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | 59 | PhononWidget::PhononWidget(QWidget *parent) | |||
---|---|---|---|---|---|
64 | m_topLayout(nullptr), | 64 | m_topLayout(nullptr), | ||
65 | m_media(nullptr), | 65 | m_media(nullptr), | ||
66 | m_seekSlider(nullptr), | 66 | m_seekSlider(nullptr), | ||
67 | m_audioOutput(nullptr), | 67 | m_audioOutput(nullptr), | ||
68 | m_videoPlayer(nullptr) | 68 | m_videoPlayer(nullptr) | ||
69 | { | 69 | { | ||
70 | } | 70 | } | ||
71 | 71 | | |||
72 | void PhononWidget::setUrl(const QUrl &url) | 72 | void PhononWidget::setUrl(const QUrl &url, MediaKind kind) | ||
73 | { | 73 | { | ||
broulik: Add a context `this` or else it will crash when timer fires with the widget being gone:
```… | |||||
meven: Thanks I thought I could not use this as context in a connect. | |||||
74 | if (m_url != url) { | 74 | if (m_url != url) { | ||
75 | stop(); // emits playingStopped() signal | | |||
76 | m_url = url; | 75 | m_url = url; | ||
76 | m_isVideo = kind == MediaKind::Video; | ||||
77 | } | ||||
78 | if (m_autoPlay) { | ||||
79 | play(); | ||||
80 | } else { | ||||
81 | stop(); | ||||
82 | } | ||||
83 | } | ||||
84 | | ||||
85 | void PhononWidget::setAutoPlay(bool autoPlay) | ||||
86 | { | ||||
87 | m_autoPlay = autoPlay; | ||||
88 | if (!m_url.isEmpty() && (m_media == nullptr || m_media->state() != Phonon::State::PlayingState) && m_autoPlay && isVisible()) { | ||||
89 | play(); | ||||
77 | } | 90 | } | ||
78 | } | 91 | } | ||
79 | 92 | | |||
80 | QUrl PhononWidget::url() const | 93 | QUrl PhononWidget::url() const | ||
81 | { | 94 | { | ||
82 | return m_url; | 95 | return m_url; | ||
83 | } | 96 | } | ||
84 | 97 | | |||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | 118 | if (!m_topLayout) { | |||
143 | // interface gets noticeable blocked, the creation is delayed until | 156 | // interface gets noticeable blocked, the creation is delayed until | ||
144 | // the play button has been pressed (see PhononWidget::play()). | 157 | // the play button has been pressed (see PhononWidget::play()). | ||
145 | } | 158 | } | ||
146 | } | 159 | } | ||
147 | 160 | | |||
148 | void PhononWidget::hideEvent(QHideEvent *event) | 161 | void PhononWidget::hideEvent(QHideEvent *event) | ||
149 | { | 162 | { | ||
150 | QWidget::hideEvent(event); | 163 | QWidget::hideEvent(event); | ||
151 | if (!event->spontaneous()) { | 164 | if (!event->spontaneous()) { | ||
152 | stop(); | 165 | stop(); | ||
153 | } | 166 | } | ||
154 | } | 167 | } | ||
155 | 168 | | |||
156 | void PhononWidget::stateChanged(Phonon::State newstate) | 169 | void PhononWidget::stateChanged(Phonon::State newstate) | ||
157 | { | 170 | { | ||
158 | setUpdatesEnabled(false); | 171 | setUpdatesEnabled(false); | ||
159 | switch (newstate) { | 172 | switch (newstate) { | ||
160 | case Phonon::PlayingState: | 173 | case Phonon::PlayingState: | ||
161 | case Phonon::BufferingState: | 174 | case Phonon::BufferingState: | ||
162 | m_stopButton->show(); | 175 | m_stopButton->show(); | ||
163 | m_playButton->hide(); | 176 | m_playButton->hide(); | ||
164 | break; | 177 | break; | ||
elvisangelaccio: Maybe an if-else would be nicer here. | |||||
165 | case Phonon::StoppedState: | | |||
166 | if (m_videoPlayer) { | | |||
167 | m_videoPlayer->hide(); | | |||
168 | } | | |||
169 | emit hasVideoChanged(false); | | |||
170 | Q_FALLTHROUGH(); | | |||
171 | default: | 178 | default: | ||
172 | m_stopButton->hide(); | 179 | m_stopButton->hide(); | ||
173 | m_playButton->show(); | 180 | m_playButton->show(); | ||
174 | break; | 181 | break; | ||
175 | } | 182 | } | ||
176 | setUpdatesEnabled(true); | 183 | setUpdatesEnabled(true); | ||
177 | } | 184 | } | ||
178 | 185 | | |||
179 | void PhononWidget::play() | 186 | void PhononWidget::play() | ||
180 | { | 187 | { | ||
181 | if (!m_media) { | 188 | if (!m_media) { | ||
182 | m_media = new Phonon::MediaObject(this); | 189 | m_media = new Phonon::MediaObject(this); | ||
183 | connect(m_media, &Phonon::MediaObject::stateChanged, | 190 | connect(m_media, &Phonon::MediaObject::stateChanged, | ||
184 | this, &PhononWidget::stateChanged); | 191 | this, &PhononWidget::stateChanged); | ||
185 | connect(m_media, &Phonon::MediaObject::hasVideoChanged, | 192 | connect(m_media, &Phonon::MediaObject::finished, | ||
186 | this, &PhononWidget::slotHasVideoChanged); | 193 | this, &PhononWidget::finished); | ||
187 | m_seekSlider->setMediaObject(m_media); | 194 | m_seekSlider->setMediaObject(m_media); | ||
188 | } | 195 | } | ||
189 | 196 | | |||
190 | if (!m_videoPlayer) { | 197 | if (!m_videoPlayer) { | ||
191 | m_videoPlayer = new EmbeddedVideoPlayer(this); | 198 | m_videoPlayer = new EmbeddedVideoPlayer(this); | ||
199 | m_videoPlayer->installEventFilter(this); | ||||
192 | m_topLayout->insertWidget(0, m_videoPlayer); | 200 | m_topLayout->insertWidget(0, m_videoPlayer); | ||
193 | Phonon::createPath(m_media, m_videoPlayer); | 201 | Phonon::createPath(m_media, m_videoPlayer); | ||
194 | applyVideoSize(); | 202 | applyVideoSize(); | ||
195 | } | 203 | } | ||
196 | 204 | | |||
197 | if (!m_audioOutput) { | 205 | if (!m_audioOutput) { | ||
198 | m_audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); | 206 | m_audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); | ||
199 | Phonon::createPath(m_media, m_audioOutput); | 207 | Phonon::createPath(m_media, m_audioOutput); | ||
200 | } | 208 | } | ||
201 | 209 | | |||
202 | emit hasVideoChanged(false); | 210 | if (m_isVideo) { | ||
211 | emit hasVideoChanged(true); | ||||
212 | } | ||||
203 | 213 | | |||
214 | if (m_url != m_media->currentSource().url()) { | ||||
204 | m_media->setCurrentSource(m_url); | 215 | m_media->setCurrentSource(m_url); | ||
205 | m_media->hasVideo(); | 216 | } | ||
206 | m_media->play(); | 217 | m_media->play(); | ||
218 | | ||||
219 | m_videoPlayer->setVisible(m_isVideo); | ||||
207 | } | 220 | } | ||
208 | 221 | | |||
209 | void PhononWidget::stop() | 222 | void PhononWidget::finished() | ||
210 | { | 223 | { | ||
211 | if (m_media) { | 224 | if (m_isVideo) { | ||
212 | m_media->stop(); | 225 | m_videoPlayer->hide(); | ||
226 | emit hasVideoChanged(false); | ||||
213 | } | 227 | } | ||
214 | } | 228 | } | ||
215 | 229 | | |||
216 | void PhononWidget::slotHasVideoChanged(bool hasVideo) | 230 | void PhononWidget::stop() | ||
217 | { | 231 | { | ||
218 | emit hasVideoChanged(hasVideo); | 232 | if (m_media) { | ||
219 | 233 | m_media->stop(); | |||
220 | if (hasVideo) { | 234 | m_videoPlayer->hide(); | ||
221 | m_videoPlayer->show(); | 235 | emit hasVideoChanged(false); | ||
222 | } | 236 | } | ||
223 | } | 237 | } | ||
224 | 238 | | |||
225 | void PhononWidget::applyVideoSize() | 239 | void PhononWidget::applyVideoSize() | ||
226 | { | 240 | { | ||
227 | if ((m_videoPlayer) && m_videoSize.isValid()) { | 241 | if ((m_videoPlayer) && m_videoSize.isValid()) { | ||
228 | m_videoPlayer->setSizeHint(m_videoSize); | 242 | m_videoPlayer->setSizeHint(m_videoSize); | ||
229 | } | 243 | } | ||
230 | } | 244 | } | ||
231 | 245 | | |||
232 | #include "phononwidget.moc" | 246 | #include "phononwidget.moc" |
Add a context this or else it will crash when timer fires with the widget being gone:
You can also probably just connect to &PhononWidget::play directly without a lambda