Guest User

Untitled

a guest
Oct 17th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1.  
  2. public static void playAll(Context context, List<Playable> list, int position, boolean openNP) {
  3. playAll(context, list, position, openNP, false);
  4. }
  5.  
  6. public static void playAll(Context context, List<Playable> list, int position, boolean openNP, boolean force_shuffle) {
  7. if (list.size() == 0 || sService == null) {
  8. Log.d("MusicUtils", "attempt to play empty song list"); // TODO
  9. // localize
  10. // Don't try to play empty playlists. Nothing good will come of it.
  11. String message = context.getString(R.string.msg_emptyplaylist,
  12. list.size());
  13. Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
  14. return;
  15. }
  16. try {
  17. if (force_shuffle) {
  18. sService.setShuffleMode(MediaPlaybackService.SHUFFLE_NORMAL);
  19. Intent intent = new Intent(MediaPlaybackService.SETSHUFFLE_ACTION);
  20. intent.putExtra("status", MediaPlaybackService.SHUFFLE_NORMAL);
  21. intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
  22. context.sendBroadcast(intent);
  23. }
  24. long curid = sService.getAudioId();
  25. int curpos = sService.getQueuePosition();
  26. // TODO FIXME Reenable this for playables!!
  27. // if (position != -1 && curpos == position && curid == list[position]) {
  28. // // The selected file is the file that's currently playing;
  29. // // figure out if we need to restart with a new playlist,
  30. // // or just launch the playback activity.
  31. // long[] playlist = sService.getQueue();
  32. // if (Arrays.equals(list, playlist)) {
  33. // // we don't need to set a new list, but we should resume
  34. // // playback if needed
  35. // sService.play();
  36. // return; // the 'finally' block will still run
  37. // }
  38. // }
  39. if (position < 0) {
  40. position = 0;
  41. }
  42. sService.openPlayables(list, position);
  43. sService.play();
  44. } catch (Exception ex) {
  45. } finally {
  46. if (!openNP)
  47. return;
  48.  
  49. if (context instanceof Activity) {
  50. SlidingDrawer slidingDrawer = (SlidingDrawer) ((Activity) context)
  51. .findViewById(R.id.SlidingDrawer);
  52. if (slidingDrawer != null) {
  53. if (!slidingDrawer.isOpened()) {
  54. slidingDrawer.animateOpen();
  55. }
  56. return;
  57. }
  58. }
  59.  
  60. Intent intent = new Intent(context, MediaPlaybackActivity.class)
  61. .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  62. context.startActivity(intent);
  63. }
  64. }
Add Comment
Please, Sign In to add comment