Author Topic: MusicBee API  (Read 287360 times)

Piotr

  • Newbie
  • *
  • Posts: 4
Is the PlayerRepeatChanged notification sent correctly by MB?
I can read the RepeadMode enum with the mbApiInterface.Player_GetRepeat() function, but unfortunately I don't receive this notification, hence my question.

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34351
it looks the plugin initialisation needs to include the tag notifications for it to be received
            about.ReceiveNotifications = (ReceiveNotificationFlags.PlayerEvents | ReceiveNotificationFlags.TagEvents);

Piotr

  • Newbie
  • *
  • Posts: 4

boroda

  • Sr. Member
  • ****
  • Posts: 4595
using MB 3.6.8736 P:

go to prefs> tags (2)> configure fields. tag "time" has type "String" (hard-coded). but Setting_GetDataType() returns type "DataType.DateTime".

i think all tag types displayed in prefs and returned by API must be consistent. as for tag "time" i would prefer if it had type "DateTime" both in prefs and returned by API.

BoringName

  • Full Member
  • ***
  • Posts: 209
Hi,

Just checking if it's possible to get all songs with the same AlbumUniqueId without iterating over the whole library.

I tried
Library_QueryFilesEx("AlbumUniqueId=xxxxxxxxxx", out songList)

Also with a query
Code
string query = "<SmartPlaylist>\n";
            query += "<Source Type=\"1\">\n";
            query += "<Conditions CombineMethod=\"All\">\n";
            query += "<Condition Field=\"AlbumUniqueId\" Comparison=\"Is\" Value=\"" + albumUniqueId + "\" />\n";
            query += "</Conditions>\n";
            query += "</Source>\n";
            query += "</SmartPlaylist>\n";

AlbumUniqueId is not listed in the dropdown when creating a smart playlist and I tried setting it to any field to match a particular AlbumUniqueId but it didn't find any matches.

I've gotten by just getting matches for album name and album artist but I think AlbumUniqueId would be more accurate.

Thanks.

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34351
I've gotten by just getting matches for album name and album artist but I think AlbumUniqueId would be more accurate.
thats right. I will have a look tonight

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34351
I tried
Library_QueryFilesEx("AlbumUniqueId=xxxxxxxxxx", out songList)
this definitely works, i expect the 2nd approach would as well. The matching files need to be in the music library, audiobooks or inbox


BoringName

  • Full Member
  • ***
  • Posts: 209
I don't know how many times I tried this the other day and just couldn't get it to work with either approach.....it was a lot.

Just tried again after reading your reply and it worked first go with the first method. No idea what I was doing wrong. Thanks.

BoringName

  • Full Member
  • ***
  • Posts: 209
First off. Is there an API command that replicates the Right Click->Play More->Play Album Now option? If there is you can probably ignore the rest of the post.

Edit: Before you waste time reading this stupidly long post. I fixed the problem. Solution posted below.

I couldn't find one so I used the following code to try and replicate it.
Code
Plugin.MbApiInterface.Library_QueryFilesEx("AlbumUniqueId=" + uniqueAlbumId, out songsList);
if (songsList.Length > 0)
{
    Plugin.MbApiInterface.NowPlayingList_PlayNow(songsList[0]);
    if (songsList.Length > 1)
        {
            songsList = songsList.Skip(1).ToArray();//remove first song from array
            Plugin.MbApiInterface.NowPlayingList_QueueFilesNext(songsList);
        }
}

Ok strap in, this is going to be a bastard to explain.

When the now playing list is empty. This works as intended. But if the list is populated and already playing something, instead of playing the first song from the album I am trying to play now, it just starts playing whatever the next song in the now playing list was and queues up all the songs from the album I select next. But it puts the first song at the end of the current album in the list.

This might be a better way to explain it. Each letter is songs from an album in the now playing list. E is one album, D is another etc...
Lets say the list looks like the following and the * is the current song playing.
D*
D
D
D
F
F
F

Now if I want to play album now for Album G.
Instead of looking like this -
D
G*
G
G
G
D
D
D
F
F
F
It looks like this -
D
D*
G
G
G
D
D
G <-- this song should be playing now. But instead it's inserted after Album D.
F
F
F

This only occurs if I try play now(using my code above) on 2 albums in a row without letting the song change. If I play now on an album, let the song fully play through so it goes to a second song, then play now on a second album, it will work correctly. Or I can manually double click a different song then play now on a second album and it works. It's only if I play now on an album and then try a second album while that first song is still playing. And it doesn't appear to matter how far through that song has played.

Also
Plugin.MbApiInterface.Library_QueryFilesEx("AlbumUniqueId=" + uniqueAlbumId, out songsList);

The output string array is not in track number order. Is there a way to do that or do I have to query all the songs in the array to sort it myself?

Using the Right Click->Play More->Play Album Now option works as you would expect and queues the songs in track number order.

It's a strange one.

edit: Ok I might be wrong about the track number order. It does appear to be in order for most but I do have one album that seems to be out of order. But it only has 3 tracks labelled as 2 of 11, 5 of 11 and 11 of 11. The last 2 are out of order,  I'll do some more testing on that one.

edit2: So most albums are coming through in track order but lucky me the first one I just happened to test initially did not. I've tried a bunch of things but they don't come through in track order.
The album Arrival by ABBA. I only have 3 songs in this library from that album
Dancing Queen track 2 of 11
Knowing Me Knowing You track 5 of 11
Fernando track 11 of 11

All other info for each track is the same. Sorting tab is the same. But for whatever reason, Fernando always comes through second in the array instead of third.

Tried changing the track numbers to 1, 2, 3. deleting the 11 field. I even renamed the file names to put the track numbers at the start of the song name like the rest of the library has and Fernando still comes through second.

I can go through and sort them myself but figured you might be interested if it's not working as intended.
Last Edit: January 22, 2024, 10:43:21 PM by BoringName

BoringName

  • Full Member
  • ***
  • Posts: 209
If I remove the line to that queues the remainder of the album next,  it adds the first song correctly and starts playing it. So I think the issue is sending a Play Now command immediately followed by a Queue Next command. I've also found another album that doesn't come through in track number order. Maybe coincidentally it is only 3 tracks as well....

And I should probably make separate threads for these issues instead of dumping everything in here. Sorry.

edit: It also has the same problem if I replace
Code
Plugin.MbApiInterface.NowPlayingList_QueueFilesNext(songsList);

with
Code
foreach(string s in songsList)
                        {
                            Plugin.MbApiInterface.NowPlayingList_QueueNext(s);
                        }
Last Edit: January 22, 2024, 03:58:09 AM by BoringName

BoringName

  • Full Member
  • ***
  • Posts: 209
I fixed it by swapping around the code.

Code
Plugin.MbApiInterface.Library_QueryFilesEx("AlbumUniqueId=" + uniqueAlbumId, out songsList);
if (songsList.Length > 0)
{
    Plugin.MbApiInterface.NowPlayingList_QueueFilesNext(songsList);
    Plugin.MbApiInterface.NowPlayingList_PlayNow(songsList[0]);
}

I thought Plugin.MbApiInterface.NowPlayingList_PlayNow would add the song to the now playing list and start playing it.

But I think it's meant to play a song that's already in the now playing list and if that song doesn't exist in the list, it just plays the next song in the now playing list and adds the song you specified to the end of what has recently added.
Last Edit: January 22, 2024, 10:53:21 PM by BoringName

CharlieJiang

  • Newbie
  • *
  • Posts: 18
Hi Steven,

I noticed that the `RetrieveLyrics` function always receive an empty string when called. Is this intended? If so, how to read the tags and "real track title (without content within parenthesis being stripped)" of the track being queried? Currently I'm using `NowPlaying_GetFileTag`, but when requesting lyrics from the Lyrics tab of the track edit panel, the current playing track may not be the track being queried, therefore I believe there should be another way to get the track URL.

Thanks.
宇宙に始まりはあるが、終わりはない。 ---無限