Add type to metadata bundle to avoid updating previous song when it shouldn't

This commit is contained in:
Jonas Kvinge 2021-03-13 03:14:30 +01:00
parent efcdfdf612
commit 2695169514
4 changed files with 30 additions and 20 deletions

View File

@ -666,24 +666,26 @@ void Player::SeekBackward() {
void Player::EngineMetadataReceived(const Engine::SimpleMetaBundle &bundle) {
PlaylistItemPtr item = app_->playlist_manager()->active()->current_item();
if (!item) return;
if (bundle.url == item->Url()) {
Song song = item->Metadata();
bool minor = song.MergeFromSimpleMetaBundle(bundle);
app_->playlist_manager()->active()->SetStreamMetadata(item->Url(), song, minor);
return;
if (bundle.type == Engine::SimpleMetaBundle::Type_Any || bundle.type == Engine::SimpleMetaBundle::Type_Current) {
PlaylistItemPtr item = app_->playlist_manager()->active()->current_item();
if (item && bundle.url == item->Url()) {
Song song = item->Metadata();
bool minor = song.MergeFromSimpleMetaBundle(bundle);
app_->playlist_manager()->active()->SetStreamMetadata(item->Url(), song, minor);
return;
}
}
int next_row = app_->playlist_manager()->active()->next_row();
if (next_row != -1) {
PlaylistItemPtr next_item = app_->playlist_manager()->active()->item_at(next_row);
if (bundle.url == next_item->Url()) {
Song song = next_item->Metadata();
song.MergeFromSimpleMetaBundle(bundle);
next_item->SetTemporaryMetadata(song);
app_->playlist_manager()->active()->ItemChanged(next_row);
if (bundle.type == Engine::SimpleMetaBundle::Type_Any || bundle.type == Engine::SimpleMetaBundle::Type_Next) {
int next_row = app_->playlist_manager()->active()->next_row();
if (next_row != -1) {
PlaylistItemPtr next_item = app_->playlist_manager()->active()->item_at(next_row);
if (bundle.url == next_item->Url()) {
Song song = next_item->Metadata();
song.MergeFromSimpleMetaBundle(bundle);
next_item->SetTemporaryMetadata(song);
app_->playlist_manager()->active()->ItemChanged(next_row);
}
}
}

View File

@ -52,11 +52,10 @@ typedef std::vector<int16_t> Scope;
class Base : public QObject {
Q_OBJECT
protected:
protected:
Base();
public:
public:
~Base() override;
struct OutputDetails {
@ -213,7 +212,13 @@ public:
};
struct SimpleMetaBundle {
SimpleMetaBundle() : length(-1), year(-1), track(-1), filetype(Song::FileType_Unknown), samplerate(-1), bitdepth(-1), bitrate(-1) {}
SimpleMetaBundle() : type(Type_Any), length(-1), year(-1), track(-1), filetype(Song::FileType_Unknown), samplerate(-1), bitdepth(-1), bitrate(-1) {}
enum Type {
Type_Any,
Type_Current,
Type_Next,
};
Type type;
QUrl url;
QUrl stream_url;
QString title;

View File

@ -930,9 +930,11 @@ void GstEngine::StreamDiscovered(GstDiscoverer*, GstDiscovererInfo *info, GError
Engine::SimpleMetaBundle bundle;
if (discovered_url == instance->current_pipeline_->stream_url()) {
bundle.type = Engine::SimpleMetaBundle::Type_Current;
bundle.url = instance->current_pipeline_->original_url();
}
else if (discovered_url == instance->current_pipeline_->next_stream_url()) {
bundle.type = Engine::SimpleMetaBundle::Type_Next;
bundle.url = instance->current_pipeline_->next_original_url();
}
bundle.stream_url = QUrl(discovered_url);

View File

@ -926,6 +926,7 @@ void GstEnginePipeline::TagMessageReceived(GstMessage *msg) {
gst_message_parse_tag(msg, &taglist);
Engine::SimpleMetaBundle bundle;
bundle.type = Engine::SimpleMetaBundle::Type_Current;
bundle.url = original_url_;
bundle.title = ParseStrTag(taglist, GST_TAG_TITLE);
bundle.artist = ParseStrTag(taglist, GST_TAG_ARTIST);