Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: How to get title & artist of current playing track (Read 3100 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

How to get title & artist of current playing track

I want to get metadata of current playing track. I add some code in function on_playback_new_track :
Code: [Select]
void CMyElemWindow::on_playback_new_track(metadb_handle_ptr p_track) {
    file_info_impl info;
    p_track->get_info(info);
    auto mc = info.meta_get_count();
    for(int i=0;i<mc;++i) {
        result += info.info_enum_name(i);
        result += " ";
    }
    update();
    return;
}


After this function call, the value in result is "bitrate bitspersample channels codec cue_embedded encoding md5 samplerate tool".

I think I'm not doing this in correct way.
Could someone tell me how to get title & artist of current playing track?

How to get title & artist of current playing track

Reply #1
The hard way, only shown for artist.
Code: [Select]
const char * name = "artist";
file_info_impl info;
if (p_track->get_info(info)) {
  const t_size meta_index = info.meta_find(name);
  if (meta_index != pfc::infinite_size) {
    const t_size value_count = info.meta_enum_value_count(meta_index);
    for (t_size value_index = 0; value_index < value_count; ++value_index) {
      const char * value = info.meta_enum_value(meta_index, value_index);
      // TODO: Do something with value.
    }
  }
}

The easy way.
Code: [Select]
pfc::string8 artist_and_title;
p_track->format_title_legacy(NULL, artist_and_title, "%artist% - %title%", NULL);