Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void playAll(Context context, List<Playable> list, int position, boolean openNP) {
- playAll(context, list, position, openNP, false);
- }
- public static void playAll(Context context, List<Playable> list, int position, boolean openNP, boolean force_shuffle) {
- if (list.size() == 0 || sService == null) {
- Log.d("MusicUtils", "attempt to play empty song list"); // TODO
- // localize
- // Don't try to play empty playlists. Nothing good will come of it.
- String message = context.getString(R.string.msg_emptyplaylist,
- list.size());
- Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
- return;
- }
- try {
- if (force_shuffle) {
- sService.setShuffleMode(MediaPlaybackService.SHUFFLE_NORMAL);
- Intent intent = new Intent(MediaPlaybackService.SETSHUFFLE_ACTION);
- intent.putExtra("status", MediaPlaybackService.SHUFFLE_NORMAL);
- intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
- context.sendBroadcast(intent);
- }
- long curid = sService.getAudioId();
- int curpos = sService.getQueuePosition();
- // TODO FIXME Reenable this for playables!!
- // if (position != -1 && curpos == position && curid == list[position]) {
- // // The selected file is the file that's currently playing;
- // // figure out if we need to restart with a new playlist,
- // // or just launch the playback activity.
- // long[] playlist = sService.getQueue();
- // if (Arrays.equals(list, playlist)) {
- // // we don't need to set a new list, but we should resume
- // // playback if needed
- // sService.play();
- // return; // the 'finally' block will still run
- // }
- // }
- if (position < 0) {
- position = 0;
- }
- sService.openPlayables(list, position);
- sService.play();
- } catch (Exception ex) {
- } finally {
- if (!openNP)
- return;
- if (context instanceof Activity) {
- SlidingDrawer slidingDrawer = (SlidingDrawer) ((Activity) context)
- .findViewById(R.id.SlidingDrawer);
- if (slidingDrawer != null) {
- if (!slidingDrawer.isOpened()) {
- slidingDrawer.animateOpen();
- }
- return;
- }
- }
- Intent intent = new Intent(context, MediaPlaybackActivity.class)
- .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- context.startActivity(intent);
- }
- }
Add Comment
Please, Sign In to add comment