@@ -53,7 +53,7 @@ void BufferedAudioPlayer::setIndex(qsizetype index)
53
53
}
54
54
else
55
55
{
56
- next ();
56
+ next (true );
57
57
}
58
58
}
59
59
}
@@ -110,14 +110,14 @@ auto BufferedAudioPlayer::loadPlaylist() -> QFuture<void>
110
110
void BufferedAudioPlayer::handleUnsupportedMediaSource (const AudioFile &file)
111
111
{
112
112
qCWarning (gmAudioBufferedPlayer ()) << " Media type" << file.source () << " is currently not supported." ;
113
- next ();
113
+ next (true );
114
114
}
115
115
116
116
void BufferedAudioPlayer::onFileReceived (const Files::FileDataResult &result)
117
117
{
118
118
if (!result.success () || result.data ().isEmpty ())
119
119
{
120
- next ();
120
+ next (true );
121
121
return ;
122
122
}
123
123
@@ -149,8 +149,6 @@ void BufferedAudioPlayer::stop()
149
149
150
150
m_mediaPlayer.stop ();
151
151
state (AudioPlayer::State::Stopped);
152
-
153
- m_playlist->clear ();
154
152
}
155
153
156
154
void BufferedAudioPlayer::setVolume (int linear, int logarithmic)
@@ -164,14 +162,29 @@ void BufferedAudioPlayer::again()
164
162
m_mediaPlayer.setPosition (0 );
165
163
}
166
164
167
- void BufferedAudioPlayer::next ()
165
+ void BufferedAudioPlayer::next (bool withError )
168
166
{
169
167
if (!m_element || m_playlist->isEmpty ())
170
168
{
171
169
stop ();
172
170
return ;
173
171
}
174
172
173
+ if (withError)
174
+ {
175
+ auto *file = m_playlist->at (playlistIndex ());
176
+ if (file)
177
+ {
178
+ file->hadError (true );
179
+ }
180
+
181
+ if (!m_playlist->hasElementsWithoutErrors ())
182
+ {
183
+ stop ();
184
+ return ;
185
+ }
186
+ }
187
+
175
188
// Complete random
176
189
if (m_element->mode () == AudioElement::Mode::Random)
177
190
{
@@ -201,7 +214,16 @@ void BufferedAudioPlayer::next()
201
214
void BufferedAudioPlayer::onMediaPlayerPlaybackStateChanged (QMediaPlayer::PlaybackState newState)
202
215
{
203
216
qCDebug (gmAudioBufferedPlayer) << " Media player playback state changed:" << newState;
204
- if (newState == QMediaPlayer::PlayingState) state (State::Playing);
217
+ if (newState == QMediaPlayer::PlayingState)
218
+ {
219
+ state (State::Playing);
220
+
221
+ auto *file = m_playlist->at (playlistIndex ());
222
+ if (file)
223
+ {
224
+ file->hadError (false );
225
+ }
226
+ }
205
227
}
206
228
207
229
void BufferedAudioPlayer::onMediaStatusChanged (QMediaPlayer::MediaStatus status)
@@ -212,7 +234,7 @@ void BufferedAudioPlayer::onMediaStatusChanged(QMediaPlayer::MediaStatus status)
212
234
{
213
235
case QMediaPlayer::EndOfMedia:
214
236
qCDebug (gmAudioBufferedPlayer ()) << " End of media was reached, playing next file ..." ;
215
- next ();
237
+ next (false );
216
238
break ;
217
239
case QMediaPlayer::BufferingMedia:
218
240
state (State::Loading);
@@ -234,7 +256,7 @@ void BufferedAudioPlayer::onMediaPlayerErrorOccurred(QMediaPlayer::Error error,
234
256
235
257
if (error != QMediaPlayer::NoError)
236
258
{
237
- next ();
259
+ next (true );
238
260
}
239
261
}
240
262
@@ -244,7 +266,7 @@ void BufferedAudioPlayer::startPlaying()
244
266
245
267
if (m_element->mode () == AudioElement::Mode::Random)
246
268
{
247
- next ();
269
+ next (false );
248
270
return ;
249
271
}
250
272
@@ -298,14 +320,21 @@ void BufferedAudioPlayer::loadWebFile(const QString &url)
298
320
m_mediaPlayer.setSource (QUrl (url));
299
321
m_mediaPlayer.play ();
300
322
m_audioOutput.setMuted (false );
323
+
324
+ QMediaMetaData metaData;
325
+ metaData.insert (QMediaMetaData::Key::Title, " -" );
326
+ metaData.insert (QMediaMetaData::Key::Author, " -" );
327
+ metaData.insert (QMediaMetaData::Key::AlbumTitle, " -" );
328
+ metaData.insert (QMediaMetaData::Key::CoverArtImage, QImage ());
329
+ emit metaDataChanged (metaData);
301
330
}
302
331
303
332
void BufferedAudioPlayer::loadYouTubeFile (AudioFile &file)
304
333
{
305
334
const Services::VideoId id (file.url ());
306
335
if (!id.isValid ())
307
336
{
308
- next ();
337
+ next (true );
309
338
return ;
310
339
}
311
340
@@ -314,7 +343,7 @@ void BufferedAudioPlayer::loadYouTubeFile(AudioFile &file)
314
343
.then ([this , &file](const Services::YouTubeVideo &video) {
315
344
if (video.audioStreamUrl .isEmpty ())
316
345
{
317
- next ();
346
+ next (true );
318
347
return ;
319
348
}
320
349
@@ -333,7 +362,7 @@ void BufferedAudioPlayer::loadYouTubeFile(AudioFile &file)
333
362
emit metaDataChanged (metaData);
334
363
});
335
364
})
336
- .onCanceled ([this ]() { next (); });
365
+ .onCanceled ([this ]() { next (true ); });
337
366
}
338
367
339
368
void BufferedAudioPlayer::applyShuffleMode ()
0 commit comments