Stop audio playback in background when a video preview is started

This commit is contained in:
David A. Velasco 2013-03-07 17:07:58 +01:00
parent cf2ba0bc07
commit 3aacc7c0fe
2 changed files with 13 additions and 3 deletions

View file

@ -62,7 +62,8 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
private static final String MY_PACKAGE = MediaService.class.getPackage() != null ? MediaService.class.getPackage().getName() : "com.owncloud.android.media";
/// Intent actions that we are prepared to handle
public static final String ACTION_PLAY_FILE = MY_PACKAGE + ".android.media.action.PLAY_FILE";
public static final String ACTION_PLAY_FILE = MY_PACKAGE + ".action.PLAY_FILE";
public static final String ACTION_STOP_ALL = MY_PACKAGE + ".action.STOP_ALL";
/// Keys to add extras to the action
public static final String EXTRA_FILE = MY_PACKAGE + ".extra.FILE";
@ -231,6 +232,9 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
String action = intent.getAction();
if (action.equals(ACTION_PLAY_FILE)) {
processPlayFileRequest(intent);
} else if (action.equals(ACTION_STOP_ALL)) {
processStopRequest(true);
}
return START_NOT_STICKY; // don't want it to restart in case it's killed.

View file

@ -70,8 +70,6 @@ import com.owncloud.android.ui.activity.TransferServiceGetter;
import com.owncloud.android.ui.fragment.ConfirmationDialogFragment;
import com.owncloud.android.ui.fragment.FileDetailFragment;
import com.owncloud.android.ui.fragment.FileFragment;
import com.owncloud.android.ui.fragment.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
import com.owncloud.android.ui.fragment.FileFragment.ContainerActivity;
import com.owncloud.android.R;
import eu.alefzero.webdav.WebdavClient;
@ -246,12 +244,20 @@ public class PreviewMediaFragment extends SherlockFragment implements
bindMediaService();
} else if (mFile.isVideo()) {
stopAudio();
playVideo();
}
}
}
private void stopAudio() {
Intent i = new Intent(getSherlockActivity(), MediaService.class);
i.setAction(MediaService.ACTION_STOP_ALL);
getSherlockActivity().startService(i);
}
/**
* {@inheritDoc}
*/