} break;
case Event::NOW_PLAYING_CONTENT_CHANGED: {
- // Respond immediately since this notification doesn't require any info
now_playing_changed_ = Notification(true, label);
- auto response =
- RegisterNotificationResponseBuilder::MakeNowPlayingBuilder(true);
- send_message(label, false, std::move(response));
+ media_interface_->GetNowPlayingList(base::Bind(
+ &Device::HandleNowPlayingNotificationResponse, base::Unretained(this),
+ now_playing_changed_.second, true));
} break;
case Event::AVAILABLE_PLAYERS_CHANGED: {
return;
}
+ media_interface_->GetNowPlayingList(
+ base::Bind(&Device::HandleNowPlayingNotificationResponse,
+ base::Unretained(this), now_playing_changed_.second, false));
+}
+
+void Device::HandleNowPlayingNotificationResponse(
+ uint8_t label, bool interim, std::string curr_song_id,
+ std::vector<SongInfo> song_list) {
+ if (!now_playing_changed_.first) {
+ LOG(WARNING) << "Device is not registered for now playing updates";
+ return;
+ }
+
+ now_playing_ids_.clear();
+ for (const SongInfo& song : song_list) {
+ now_playing_ids_.insert(song.media_id);
+ }
+
auto response =
- RegisterNotificationResponseBuilder::MakeNowPlayingBuilder(false);
+ RegisterNotificationResponseBuilder::MakeNowPlayingBuilder(interim);
send_message(now_playing_changed_.second, false, std::move(response));
- now_playing_changed_ = Notification(false, 0);
+
+ if (!interim) {
+ active_labels_.erase(label);
+ now_playing_changed_ = Notification(false, 0);
+ }
}
void Device::HandlePlayPosUpdate() {
// NOW PLAYING LIST CHANGED
virtual void HandleNowPlayingUpdate();
+ virtual void HandleNowPlayingNotificationResponse(
+ uint8_t label, bool interim, std::string curr_song_id,
+ std::vector<SongInfo> song_list);
// PLAY POSITION CHANGED
virtual void HandlePlayPosUpdate();
test_device->RegisterInterfaces(&interface, &a2dp_interface, nullptr);
+ SongInfo info = {"test_id",
+ {// The attribute map
+ AttributeEntry(Attribute::TITLE, "Test Song"),
+ AttributeEntry(Attribute::ARTIST_NAME, "Test Artist"),
+ AttributeEntry(Attribute::ALBUM_NAME, "Test Album"),
+ AttributeEntry(Attribute::TRACK_NUMBER, "1"),
+ AttributeEntry(Attribute::TOTAL_NUMBER_OF_TRACKS, "2"),
+ AttributeEntry(Attribute::GENRE, "Test Genre"),
+ AttributeEntry(Attribute::PLAYING_TIME, "1000")}};
+ std::vector<SongInfo> list = {info};
+ EXPECT_CALL(interface, GetNowPlayingList(_))
+ .Times(2)
+ .WillRepeatedly(InvokeCb<0>("test_id", list));
+
// Test the interim response for now playing list changed
auto interim_response =
RegisterNotificationResponseBuilder::MakeNowPlayingBuilder(true);