Guest User

Untitled

a guest
May 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. public class Song implements Serializable {
  2.  
  3. private String title;
  4. private String artist;
  5. private String path;
  6. private String displayName;
  7. private String songDuration;
  8. private long album_id;
  9.  
  10. // Геттеры и сеттеры
  11.  
  12. // Получаем длительность песни в удобном формате MM:SS
  13. public String getFormattedSongDuration() throws ParseException {
  14. return DateUtils.formatElapsedTime(Long.parseLong(songDuration)/1000);
  15. }
  16.  
  17. // Генерируем URI для получения картинки альбома песни
  18. public Uri getAlbumArtUri() {
  19. Uri base = Uri.parse("content://media/external/audio/albumart");
  20. return ContentUris.withAppendedId(base, album_id);
  21. }
  22. }
  23.  
  24. // ======================================
  25.  
  26. // playlist - объект класса Playlist, который хранит
  27. // список песен и содержит некоторые методы управления
  28. // списком песен
  29. @Override
  30. public View getView(int position, View convertView, ViewGroup parent) {
  31.  
  32. View view = convertView;
  33.  
  34. if (view == null) {
  35. LayoutInflater inflater = (LayoutInflater)
  36. context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  37. view = inflater.inflate(R.layout.playlist_item, parent, false);
  38. }
  39.  
  40. // Выводим порядковый номер песни
  41. TextView song_position = (TextView) view.findViewById(R.id.position);
  42. song_position.setText(String.valueOf(position + 1) + ".");
  43.  
  44. // Выводим название исполнителя
  45. TextView song_artist = (TextView) view.findViewById(R.id.artist);
  46. song_artist.setText(playlist.getSongAtPosition(position).getArtist());
  47.  
  48. // Выводим название песни
  49. TextView song_title = (TextView) view.findViewById(R.id.title);
  50. song_title.setText(playlist.getSongAtPosition(position).getTitle());
  51.  
  52. // Выводим длительность песни
  53. TextView song_duration = (TextView) view.findViewById(R.id.duration);
  54. try {
  55. song_duration.setText(playlist.getSongAtPosition(position).getFormattedSongDuration());
  56. } catch (ParseException e) {
  57. e.printStackTrace();
  58. }
  59.  
  60. // Выводим картинку
  61. Bitmap bitmap = null;
  62. ContentResolver resolver = view.getContext().getContentResolver();
  63. Uri uri = playlist.getSongAtPosition(position).getAlbumArtUri();
  64. try {
  65. bitmap = MediaStore.Images.Media.getBitmap(resolver, uri);
  66. } catch (IOException e) {
  67. e.printStackTrace();
  68. }
  69.  
  70. if (bitmap != null) {
  71. ImageView cover = view.findViewById(R.id.cd_image);
  72. cover.setImageBitmap(bitmap);
  73. }
  74.  
  75. view.invalidate();
  76. return view;
  77. }
Add Comment
Please, Sign In to add comment