Issue/play from here (#713)
* Fixes race condition in MediaFileListFragment The "Play from here" feature previously queued all songs at once using a loop and did not wait until an add action was confirmed by Kodi before queueing the next item. This sometimes resulted in a seemingly random play order on Kodi. * Fixed play from here adding first item twice When selecting "Play from here" in the file browser the current item is started using "playMediaFile" and the subsequent items are queued. However, the current item was added to the queue list as well. Resulting in the first item always being added twice to the playlist.
This commit is contained in:
parent
e92722375c
commit
e63fd40d9f
|
@ -366,9 +366,9 @@ public class MediaFileListFragment extends AbstractListFragment {
|
||||||
action.execute(hostManager.getConnection(), new ApiCallback<String>() {
|
action.execute(hostManager.getConnection(), new ApiCallback<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(String result) {
|
public void onSuccess(String result) {
|
||||||
while (!mediaQueueFileLocation.isEmpty()) {
|
HostConnection connection = hostManager.getConnection();
|
||||||
queueMediaFile(mediaQueueFileLocation.poll().file);
|
startPlaylistIfNoActivePlayers(connection, playlistId, callbackHandler);
|
||||||
}
|
callbackHandler.post(queueMediaQueueFileLocations);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -381,6 +381,33 @@ public class MediaFileListFragment extends AbstractListFragment {
|
||||||
}, callbackHandler);
|
}, callbackHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Runnable queueMediaQueueFileLocations = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (!mediaQueueFileLocation.isEmpty()) {
|
||||||
|
final HostConnection connection = hostManager.getConnection();
|
||||||
|
PlaylistType.Item item = new PlaylistType.Item();
|
||||||
|
item.file = mediaQueueFileLocation.poll().file;
|
||||||
|
Playlist.Add action = new Playlist.Add(playlistId, item);
|
||||||
|
action.execute(connection, new ApiCallback<String>() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(String result ) {
|
||||||
|
callbackHandler.post(queueMediaQueueFileLocations);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(int errorCode, String description) {
|
||||||
|
if (!isAdded()) return;
|
||||||
|
Toast.makeText(getActivity(),
|
||||||
|
String.format(getString(R.string.error_queue_media_file), description),
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
callbackHandler.post(queueMediaQueueFileLocations);
|
||||||
|
}
|
||||||
|
}, callbackHandler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts playing the given media file on the local device
|
* Starts playing the given media file on the local device
|
||||||
* @param filename Filename to start playing
|
* @param filename Filename to start playing
|
||||||
|
@ -554,7 +581,6 @@ public class MediaFileListFragment extends AbstractListFragment {
|
||||||
mediaQueueFileLocation.clear();
|
mediaQueueFileLocation.clear();
|
||||||
FileLocation fl;
|
FileLocation fl;
|
||||||
// start playing the selected one, then queue the rest
|
// start playing the selected one, then queue the rest
|
||||||
mediaQueueFileLocation.add(loc);
|
|
||||||
for (int i = position + 1; i < fileLocationItems.size(); i++) {
|
for (int i = position + 1; i < fileLocationItems.size(); i++) {
|
||||||
fl = fileLocationItems.get(i);
|
fl = fileLocationItems.get(i);
|
||||||
if (!fl.isDirectory) {
|
if (!fl.isDirectory) {
|
||||||
|
|
Loading…
Reference in New Issue