Skip to content

Commit c313eda

Browse files
committed
1.2.1 release - Now Playing list is not sent in the same order it is displayed in MusicBee player
1 parent 1cd7fff commit c313eda

File tree

3 files changed

+56
-9
lines changed

3 files changed

+56
-9
lines changed

plugin/AndroidRemote/Commands/Requests/RequestNowPlayingList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void Execute(IEvent eEvent)
2424
{
2525
var offset = data.Get<int>("offset");
2626
var limit = data.Get<int>("limit");
27-
Plugin.Instance.RequestNowPlayingListPage(eEvent.ClientId, offset, limit);
27+
Plugin.Instance.RequestNowPlayingListOrdered(eEvent.ClientId, offset, limit);
2828
}
2929
}
3030
}

plugin/Plugin.cs

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,59 @@ public void RequestRepeatState(StateAction action)
688688
_api.Player_GetRepeat()).ToJsonString()));
689689
}
690690

691+
public void RequestNowPlayingListOrdered(string clientId, int offset = 0, int limit = 4000)
692+
{
693+
limit = 100;
694+
_api.NowPlayingList_QueryFiles(null);
695+
696+
var tracks = new List<NowPlaying>();
697+
var position = 1;
698+
var itemIndex = _api.NowPlayingList_GetCurrentIndex();
699+
while (position <= limit)
700+
{
701+
var trackPath = _api.NowPlayingList_GetListFileUrl(itemIndex);
702+
703+
if (string.IsNullOrEmpty(trackPath))
704+
break;
705+
706+
var artist = _api.Library_GetFileTag(trackPath, MetaDataType.Artist);
707+
var title = _api.Library_GetFileTag(trackPath, MetaDataType.TrackTitle);
708+
709+
if (string.IsNullOrEmpty(title))
710+
{
711+
var index = trackPath.LastIndexOf('\\');
712+
title = trackPath.Substring(index + 1);
713+
}
714+
715+
var track = new NowPlaying
716+
{
717+
Artist = string.IsNullOrEmpty(artist) ? "Unknown Artist" : artist,
718+
Title = title,
719+
Position = itemIndex,
720+
Path = trackPath
721+
};
722+
723+
tracks.Add(track);
724+
itemIndex = _api.NowPlayingList_GetNextIndex(position);
725+
position++;
726+
}
727+
728+
var total = tracks.Count;
729+
var message = new SocketMessage
730+
{
731+
Context = Constants.NowPlayingList,
732+
Data = new Page<NowPlaying>
733+
{
734+
Data = tracks,
735+
Offset = offset,
736+
Limit = limit,
737+
Total = total
738+
}
739+
};
740+
var messageEvent = new MessageEvent(EventType.ReplyAvailable, message.ToJsonString(), clientId);
741+
EventBus.FireEvent(messageEvent);
742+
}
743+
691744
public void RequestNowPlayingListPage(string clientId, int offset = 0, int limit = 4000)
692745
{
693746
_api.NowPlayingList_QueryFiles(null);
@@ -919,13 +972,7 @@ public void NowPlayingPlay(string index)
919972
if (int.TryParse(index, out trackIndex))
920973
{
921974
_api.NowPlayingList_QueryFiles(null);
922-
var trackToPlay = string.Empty;
923-
var lTrackIndex = 0;
924-
while (trackIndex != lTrackIndex)
925-
{
926-
trackToPlay = _api.NowPlayingList_QueryGetNextFile();
927-
lTrackIndex++;
928-
}
975+
var trackToPlay = _api.NowPlayingList_GetListFileUrl(trackIndex);
929976
if (!string.IsNullOrEmpty(trackToPlay))
930977
result = _api.NowPlayingList_PlayNow(trackToPlay);
931978
}

plugin/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@
3636
// by using the '*' as shown below:
3737
// [assembly: AssemblyVersion("1.0.*")]
3838

39-
[assembly: AssemblyVersion("1.2.0")]
39+
[assembly: AssemblyVersion("1.2.1")]

0 commit comments

Comments
 (0)