Author Topic: MusicBee API  (Read 285423 times)

dandepeched

  • Jr. Member
  • **
  • Posts: 43
NowPlayingList_MoveFiles uses the same internal functions as manually drag/dropping files, however i do see one inconsistency.
Does this version work better?
https://getmusicbee.com/patches/MusicBee34_Patched.zip

Unfortunately no, same result  :(
By the way _api.NowPlayingList_RemoveAt(index) works fine, which makes me think that retrieved indexes are correct.
Also NowPlayingList_MoveFiles works fine when Shuffle is off (so the indexes go in natural order)

If not, are you saying that you are comparing NowPlayingList_QueryFiles(null) before and after the operation that its shuffled? If so, I dont see how that would have been case so could you explain how you determined the list is re-shuffled?

I'm not comparing it in code, I see it re-shuffled in player. I think it makes sense to share the code:
1) To get Now Playing list and appropriate track indexes:
Code
public void RequestNowPlayingListOrdered(string clientId, int offset = 0, int limit = 100)
        {
            _api.NowPlayingList_QueryFiles(null);

            var tracks = new List<NowPlaying>();
            var position = 1;
            var itemIndex = _api.NowPlayingList_GetCurrentIndex();
            while (position <= limit)
            {
                var trackPath = _api.NowPlayingList_GetListFileUrl(itemIndex);

                var track = getFileMetadata(trackPath, itemIndex);

                tracks.Add(track);
                itemIndex = _api.NowPlayingList_GetNextIndex(position);
                position++;
            }

            sendDataToClient(clientId, tracks);
        }
2) To change order of Now Playing list:
Code
public void RequestNowPlayingMove(string clientId, int from, int to)
        {
            bool result;
            int[] aFrom = {from};
            int dIn;
            if (from > to)
            {
                dIn = to - 1;
            }
            else
            {
                dIn = to;
            }
            result = _api.NowPlayingList_MoveFiles(aFrom, dIn);

            sendDataToClient(clientId, result);
        }
Last Edit: February 20, 2021, 05:17:07 PM by dandepeched

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
Actually there is a flaw in the internal functions for manual file drag/drop that is causing the issue you having. I will look to fix it over the next few days


dandepeched

  • Jr. Member
  • **
  • Posts: 43
https://getmusicbee.com/patches/MusicBee34_Patched.zip

This version definitely better, but still inconsistent.
List is not reshuffled anymore, but unexpected tracks appear instead of moving track. Sometimes it works as expected, but mainly not.
Here are some consecutive observations:
Code
Initial list - "position":3939,"position":115,"position":178,"position":3693,"position":2517...
3939 is Now Playing track, so I'm not touching it.

Move "from":178,"to":115
Result "position":3939,"position":116,"position":114,"position":3693,"position":2517...
115 properly moved to 116, but 114 is a new track instead of 178 (from the same album as 116). 117 is not shown anymore.

Move "from":3693,"to":114
"position":3939,"position":117,"position":115,"position":113,"position":2518...
116 moved to 117, 114 moved to 115, but 113 is a new track instead of 3693 (from the same album as 114 and 116), 2517 moved to 2518

Move in different direction "from":117,"to":115
"position":3939,"position":114,"position":116,"position":113,"position":2518...
Where previous 3693 appears back as 114 (instead of 115), 117 moved to 116

Move "from":114,"to":116
"position":3939,"position":115,"position":116,"position":113,"position":2518...
Action consistent - everything worked as expected! (116->115, 114->116)

Let me know if any additional information is needed

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
that will teach me for making last minute optimisations. It better work this time:
https://getmusicbee.com/patches/MusicBee34_Patched.zip

dandepeched

  • Jr. Member
  • **
  • Posts: 43
that will teach me for making last minute optimisations.

A temptation for any developer  ::)

https://getmusicbee.com/patches/MusicBee34_Patched.zip

Unfortunately it is still inconsistent :(
Behavior is similar to my last observations - track from non-shuffled order (same album) appears instead of track I'm trying to move (with Now Playing shuffled order).

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
When using the API calls, the only issue i can reproduce is a minor GUI issue where MB displays the playing icon against the wrong file but is fine for subsequent files. That only happens when moving files via the API and not manual drag/drop.
Using your RequestNowPlayingListOrdered() function the list always looks fine to me after trying various move operations. I dont think I will spend more time on this.
Just in case its a misunderstanding of what NowPlayingList_MoveFiles() does - it changes the physical ordering of files in the playing tracks list which means that MB internally adjusts the indices of the upcoming tracks to match the new physical ordering of the files but it is not moving files up or down the next in sequence order

dandepeched

  • Jr. Member
  • **
  • Posts: 43
When using the API calls, the only issue i can reproduce is a minor GUI issue where MB displays the playing icon against the wrong file but is fine for subsequent files. That only happens when moving files via the API and not manual drag/drop.
Using your RequestNowPlayingListOrdered() function the list always looks fine to me after trying various move operations. I dont think I will spend more time on this.
Just in case its a misunderstanding of what NowPlayingList_MoveFiles() does - it changes the physical ordering of files in the playing tracks list which means that MB internally adjusts the indices of the upcoming tracks to match the new physical ordering of the files but it is not moving files up or down the next in sequence order

Hi Steven, just to clarify your statement, let me try to layout a scenario:
1) I have a playlist sorted by Album Artist/Year/Album
2) I start playback of this list non-shuffled and Now Playing indices are 0,1,2,3...
3) I press Shuffle and now indices are 0,2355,2367,2259...
4) I want to change Now Playing list order, so that next 2 tracks exchange their positions (2355 <-> 2367)
5) Currently I'm trying to call either _api.NowPlayingList_MoveFiles(2355, 2367); or  _api.NowPlayingList_MoveFiles(2367, 2354);

Is it correct approach? If not, how to satisfy the intention from step 4?

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
Thats an example of what i am saying. There is no api call to move files ordering within the shuffle list, just move files physical displayed ordering

dandepeched

  • Jr. Member
  • **
  • Posts: 43
Thats an example of what i am saying. There is no api call to move files ordering within the shuffle list, just move files physical displayed ordering

I would love to see such API to mirror the drag and drop functionality of MB player. Or at least some workaround API like "NowPlayingList_QueueAtPostion".
Also one more missing API which is requested by users is access to History list.

It would be great if you can consider this 2 items to be added in some future!

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
It does mirror the drag/drop functionality. When you have the shuffle button enabled and showing Playing Tracks, drag/dropping just changes the displayed order. The shuffle order is unchanged. Thats what the api does.
I am happy to add something for v3.5

dandepeched

  • Jr. Member
  • **
  • Posts: 43
It does mirror the drag/drop functionality. When you have the shuffle button enabled and showing Playing Tracks, drag/dropping just changes the displayed order. The shuffle order is unchanged. Thats what the api does.
I am happy to add something for v3.5

Sorry, I still cannot understand how it works :)
When I use MusicBee player I see following when Shuffle is enabled. After drag and drop displayed list is always re-ordered as expected:
https://imgur.com/a/b17YLS8

But I cannot mirror that behavior with API as I explained in my previous posts. When I try to "move" with indexes, sometimes unexpected files appears in the displayed list.
What am I doing wrong?
Last Edit: March 04, 2021, 10:56:15 AM by dandepeched

dandepeched

  • Jr. Member
  • **
  • Posts: 43
I made a short video which shows incorrect displayed order - https://drive.google.com/file/d/11YcLtTQO2KDk4mmojB3vq6AsFm0inWNZ/view?usp=sharing
Steps:
1) Select Play Shuffled for some playlist
2) Go to Now Playing tab to observe the API call result
3) With the API move "The Creation" track to the previous position (which is "Graduation of the Soul")
4) Observe that "The Creation" track disappears and "The Land of Pan" track appears instead of it (which has a neighbor index for "Graduation of the Soul")

Funny thing that sometimes re-order works as expected. As a next step I moved "Graduation of the Soul" to the previous position ("Horizon") and this time it worked as expected!

I still believe there is a bug with the API. Please try to reproduce it by moving same 2 files in different direction few times (move down, than move back up, vice versa, etc)
Last Edit: March 04, 2021, 11:03:36 AM by dandepeched

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
You are showing the "upcoming tracks" which is the order within the shuffle list ie. the order that tracks will play on completion of each track or clicking the next track button. Thats not the same as the order of the tracks on  the "playing tracks" list eg. you might have tracks 1,2,3,4 from an album on the playing tracks list (switch the view to "playing tracks" and it will show the tracks in order 1,2,3,4) but when shuffle is enabled the tracks might play in order 3,1,2,4. In the upcoming tracks view the display order will be 3,1,2,4
The api is moving the order of tracks in the playing tracks list, not the sequence within the shuffle order.

Having said that, there might be a display bug in the upcoming tracks view as i would expect the moving tracks with api call would have no effect on the tracks displayed in that view.
But it doesnt change that the api is not moving tracks in the shuffle order


dandepeched

  • Jr. Member
  • **
  • Posts: 43
You are showing the "upcoming tracks" which is the order within the shuffle list

Thanks for explanation! So is there an API to mirror drag and drop action for "Upcoming Tracks" list?
If not, than it would be great to add it in v3.5 :) In my opinion this is important, as it seems to be the only way to edit shuffled order.