@@ -912,6 +912,54 @@ class MusifyAudioHandler extends BaseAudioHandler {
912912 }
913913 }
914914
915+ Future <void > reorderQueueById (String queueEntryId, int targetIndex) async {
916+ try {
917+ _queueEntryIds.ensureIds (_queueList);
918+
919+ final oldIndex = _queueList.indexWhere (
920+ (s) => _queueEntryIds.ensureId (s) == queueEntryId,
921+ );
922+ if (oldIndex == - 1 ) return ;
923+
924+ // Clamp target index to valid range (allow insert at end)
925+ if (targetIndex < 0 ) targetIndex = 0 ;
926+ if (targetIndex > _queueList.length) targetIndex = _queueList.length;
927+
928+ final song = _queueList.removeAt (oldIndex);
929+ var newIndex = targetIndex;
930+ if (newIndex > _queueList.length) newIndex = _queueList.length;
931+ _queueList.insert (newIndex, song);
932+
933+ if (oldIndex == _currentQueueIndex) {
934+ _currentQueueIndex = newIndex;
935+ } else if (oldIndex < _currentQueueIndex &&
936+ newIndex >= _currentQueueIndex) {
937+ _currentQueueIndex-- ;
938+ } else if (oldIndex > _currentQueueIndex &&
939+ newIndex <= _currentQueueIndex) {
940+ _currentQueueIndex++ ;
941+ }
942+
943+ if (oldIndex == _currentLoadingIndex) {
944+ _currentLoadingIndex = newIndex;
945+ } else if (oldIndex < _currentLoadingIndex &&
946+ newIndex >= _currentLoadingIndex) {
947+ _currentLoadingIndex-- ;
948+ } else if (oldIndex > _currentLoadingIndex &&
949+ newIndex <= _currentLoadingIndex) {
950+ _currentLoadingIndex++ ;
951+ }
952+
953+ _updateQueueMediaItems ();
954+ } catch (e, stackTrace) {
955+ logger.log (
956+ 'Error reordering queue by id' ,
957+ error: e,
958+ stackTrace: stackTrace,
959+ );
960+ }
961+ }
962+
915963 void clearQueue () {
916964 try {
917965 _queueList.clear ();
0 commit comments