Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal music player does not stop playing when file is deleted #1292

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/com/owncloud/android/media/MediaService.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
/// Intent actions that we are prepared to handle
public static final String ACTION_PLAY_FILE = MY_PACKAGE + ".action.PLAY_FILE";
public static final String ACTION_STOP_ALL = MY_PACKAGE + ".action.STOP_ALL";
public static final String ACTION_STOP_FILE = MY_PACKAGE + ".action.STOP_FILE";

/// Keys to add extras to the action
public static final String EXTRA_FILE = MY_PACKAGE + ".extra.FILE";
Expand Down Expand Up @@ -244,11 +245,25 @@ public int onStartCommand(Intent intent, int flags, int startId) {

} else if (action.equals(ACTION_STOP_ALL)) {
processStopRequest(true);
} else if(action.equals(ACTION_STOP_FILE)) {
processStopFileRequest(intent);
}

return START_NOT_STICKY; // don't want it to restart in case it's killed.
}

private void processStopFileRequest(Intent intent) {
OCFile file = intent.getExtras().getParcelable(EXTRA_FILE);
try {
if(file.equals(mFile)) {
processStopRequest(true);
}
}
catch (NullPointerException e) {
Log_OC.e(TAG, "NullPointerException while stopping on OCFile ", e);
}
}


/**
* Processes a request to play a media file received as a parameter
Expand Down
33 changes: 20 additions & 13 deletions src/com/owncloud/android/ui/dialog/RemoveFileDialogFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@

/**
* Dialog requiring confirmation before removing a given OCFile.
*
*
* Triggers the removal according to the user response.
*/

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;

import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.media.MediaService;
import com.owncloud.android.ui.activity.ComponentsGetter;
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;

public class RemoveFileDialogFragment extends ConfirmationDialogFragment
public class RemoveFileDialogFragment extends ConfirmationDialogFragment
implements ConfirmationDialogFragmentListener {

private OCFile mTargetFile;
Expand All @@ -44,16 +46,16 @@ public class RemoveFileDialogFragment extends ConfirmationDialogFragment

/**
* Public factory method to create new RemoveFileDialogFragment instances.
*
*
* @param file File to remove.
* @return Dialog ready to show.
*/
public static RemoveFileDialogFragment newInstance(OCFile file) {
RemoveFileDialogFragment frag = new RemoveFileDialogFragment();
Bundle args = new Bundle();

int messageStringId = R.string.confirmation_remove_alert;

int posBtn = R.string.confirmation_remove_remote;
int negBtn = -1;
if (file.isFolder()) {
Expand All @@ -64,27 +66,27 @@ public static RemoveFileDialogFragment newInstance(OCFile file) {
posBtn = R.string.confirmation_remove_remote_and_local;
negBtn = R.string.confirmation_remove_local;
}

args.putInt(ARG_CONF_RESOURCE_ID, messageStringId);
args.putStringArray(ARG_CONF_ARGUMENTS, new String[]{file.getFileName()});
args.putInt(ARG_POSITIVE_BTN_RES, posBtn);
args.putInt(ARG_NEUTRAL_BTN_RES, R.string.common_no);
args.putInt(ARG_NEGATIVE_BTN_RES, negBtn);
args.putParcelable(ARG_TARGET_FILE, file);
frag.setArguments(args);

return frag;
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
mTargetFile = getArguments().getParcelable(ARG_TARGET_FILE);

setOnConfirmationListener(this);

return dialog;
}
}

/**
* Performs the removal of the target file, both locally and in the server.
Expand All @@ -93,11 +95,16 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
public void onConfirmation(String callerTag) {
ComponentsGetter cg = (ComponentsGetter)getActivity();
FileDataStorageManager storageManager = cg.getStorageManager();
if (storageManager.getFileById(mTargetFile.getFileId()) != null) {
OCFile ocFile = storageManager.getFileById(mTargetFile.getFileId());
if (ocFile != null) {
cg.getFileOperationsHelper().removeFile(mTargetFile, false);
Intent i = new Intent(getActivity(), MediaService.class);
i.putExtra(MediaService.EXTRA_FILE, ocFile);
i.setAction(MediaService.ACTION_STOP_FILE);
getActivity().startService(i);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if you set this behaviour also for a local remove, since it makes sense that if you want to remove the file locally, you don't want to keep it in the buffer of the media service.

P.D: The local remove listener is currently set in the negative button (which listener mehotd is onCancel). Extract to a new method to reuse the MediaService call.

}
}

/**
* Performs the removal of the local copy of the target file
*/
Expand Down