mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 23:28:42 +03:00
Merge pull request #1114 from nextcloud/fix_bug_stop_player_when_delete_file
Fix bug stop player when delete file
This commit is contained in:
commit
63251d6009
2 changed files with 49 additions and 0 deletions
|
@ -74,6 +74,8 @@ import com.owncloud.android.lib.common.operations.RemoteOperation;
|
|||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.media.MediaService;
|
||||
import com.owncloud.android.media.MediaServiceBinder;
|
||||
import com.owncloud.android.operations.CopyFileOperation;
|
||||
import com.owncloud.android.operations.CreateFolderOperation;
|
||||
import com.owncloud.android.operations.MoveFileOperation;
|
||||
|
@ -166,6 +168,9 @@ public class FileDisplayActivity extends HookActivity
|
|||
|
||||
private Collection<MenuItem> mDrawerMenuItemstoShowHideList;
|
||||
|
||||
private MediaServiceBinder mMediaServiceBinder = null;
|
||||
private MediaServiceConnection mMediaServiceConnection = null;
|
||||
|
||||
private String searchQuery;
|
||||
|
||||
private SearchView searchView;
|
||||
|
@ -1600,8 +1605,38 @@ public class FileDisplayActivity extends HookActivity
|
|||
mUploaderBinder = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private MediaServiceConnection newMediaConnection(){
|
||||
return new MediaServiceConnection();
|
||||
}
|
||||
|
||||
/** Defines callbacks for service binding, passed to bindService() */
|
||||
private class MediaServiceConnection implements ServiceConnection {
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName component, IBinder service) {
|
||||
|
||||
if (component.equals(new ComponentName(FileDisplayActivity.this, MediaService.class))) {
|
||||
Log_OC.d(TAG, "Media service connected");
|
||||
mMediaServiceBinder = (MediaServiceBinder) service;
|
||||
|
||||
}else {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName component) {
|
||||
if (component.equals(new ComponentName(FileDisplayActivity.this,
|
||||
MediaService.class))) {
|
||||
Log_OC.e(TAG, "Media service disconnected");
|
||||
mMediaServiceBinder = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the view associated to the activity after the finish of some operation over files
|
||||
* in the current account.
|
||||
|
@ -1669,6 +1704,7 @@ public class FileDisplayActivity extends HookActivity
|
|||
|
||||
if (result.isSuccess()) {
|
||||
OCFile removedFile = operation.getFile();
|
||||
tryStopPlaying(removedFile);
|
||||
FileFragment second = getSecondFragment();
|
||||
if (second != null && removedFile.equals(second.getFile())) {
|
||||
if (second instanceof PreviewMediaFragment) {
|
||||
|
@ -1689,6 +1725,16 @@ public class FileDisplayActivity extends HookActivity
|
|||
}
|
||||
}
|
||||
|
||||
public void setMediaServiceConnection() {
|
||||
mMediaServiceConnection = newMediaConnection();// mediaServiceConnection;
|
||||
bindService(new Intent(this, MediaService.class), mMediaServiceConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
private void tryStopPlaying(OCFile file) {
|
||||
if (mMediaServiceConnection != null && MimeTypeUtil.isAudio(file) && mMediaServiceBinder.isPlaying(file)) {
|
||||
mMediaServiceBinder.pause();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the view associated to the activity after the finish of an operation trying to move a
|
||||
|
|
|
@ -62,6 +62,7 @@ import com.owncloud.android.media.MediaControlView;
|
|||
import com.owncloud.android.media.MediaService;
|
||||
import com.owncloud.android.media.MediaServiceBinder;
|
||||
import com.owncloud.android.ui.activity.FileActivity;
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
||||
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
|
||||
import com.owncloud.android.ui.dialog.RemoveFilesDialogFragment;
|
||||
import com.owncloud.android.ui.fragment.FileFragment;
|
||||
|
@ -692,6 +693,8 @@ public class PreviewMediaFragment extends FileFragment implements
|
|||
mMediaServiceConnection,
|
||||
Context.BIND_AUTO_CREATE);
|
||||
// follow the flow in MediaServiceConnection#onServiceConnected(...)
|
||||
|
||||
((FileDisplayActivity) getActivity()).setMediaServiceConnection();
|
||||
}
|
||||
|
||||
/** Defines callbacks for service binding, passed to bindService() */
|
||||
|
|
Loading…
Reference in a new issue