mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 23:28:42 +03:00
Media player stops when its current file is deleted
This commit is contained in:
parent
4e013b5bb6
commit
722afd6519
2 changed files with 65 additions and 0 deletions
|
@ -38,6 +38,9 @@ import android.content.SharedPreferences;
|
|||
import android.content.SyncRequest;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources.NotFoundException;
|
||||
import android.database.Cursor;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
|
@ -74,6 +77,9 @@ 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;
|
||||
|
@ -165,6 +171,8 @@ public class FileDisplayActivity extends HookActivity
|
|||
private OCFile mWaitingToSend;
|
||||
|
||||
private Collection<MenuItem> mDrawerMenuItemstoShowHideList;
|
||||
private MediaServiceBinder mMediaServiceBinder = null;
|
||||
private MediaServiceConnection mMediaServiceConnection = null;
|
||||
|
||||
private String searchQuery;
|
||||
|
||||
|
@ -1600,6 +1608,44 @@ 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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onSavedCertificate() {
|
||||
startSyncFolderOperation(getCurrentDir(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1669,6 +1715,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 +1736,21 @@ public class FileDisplayActivity extends HookActivity
|
|||
}
|
||||
}
|
||||
|
||||
public void setMediaServiceConnection() {
|
||||
mMediaServiceConnection = newMediaConnection();// mediaServiceConnection;
|
||||
if (mMediaServiceConnection != null) {
|
||||
bindService(new Intent(this, MediaService.class), mMediaServiceConnection,
|
||||
Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
}
|
||||
|
||||
private void tryStopPlaying(OCFile file){
|
||||
if (mMediaServiceConnection != null && file.isAudio()){
|
||||
if (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