Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Song implements Serializable {
- private String title;
- private String artist;
- private String path;
- private String displayName;
- private String songDuration;
- private long album_id;
- // Геттеры и сеттеры
- // Получаем длительность песни в удобном формате MM:SS
- public String getFormattedSongDuration() throws ParseException {
- return DateUtils.formatElapsedTime(Long.parseLong(songDuration)/1000);
- }
- // Генерируем URI для получения картинки альбома песни
- public Uri getAlbumArtUri() {
- Uri base = Uri.parse("content://media/external/audio/albumart");
- return ContentUris.withAppendedId(base, album_id);
- }
- }
- // ======================================
- // playlist - объект класса Playlist, который хранит
- // список песен и содержит некоторые методы управления
- // списком песен
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- View view = convertView;
- if (view == null) {
- LayoutInflater inflater = (LayoutInflater)
- context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- view = inflater.inflate(R.layout.playlist_item, parent, false);
- }
- // Выводим порядковый номер песни
- TextView song_position = (TextView) view.findViewById(R.id.position);
- song_position.setText(String.valueOf(position + 1) + ".");
- // Выводим название исполнителя
- TextView song_artist = (TextView) view.findViewById(R.id.artist);
- song_artist.setText(playlist.getSongAtPosition(position).getArtist());
- // Выводим название песни
- TextView song_title = (TextView) view.findViewById(R.id.title);
- song_title.setText(playlist.getSongAtPosition(position).getTitle());
- // Выводим длительность песни
- TextView song_duration = (TextView) view.findViewById(R.id.duration);
- try {
- song_duration.setText(playlist.getSongAtPosition(position).getFormattedSongDuration());
- } catch (ParseException e) {
- e.printStackTrace();
- }
- // Выводим картинку
- Bitmap bitmap = null;
- ContentResolver resolver = view.getContext().getContentResolver();
- Uri uri = playlist.getSongAtPosition(position).getAlbumArtUri();
- try {
- bitmap = MediaStore.Images.Media.getBitmap(resolver, uri);
- } catch (IOException e) {
- e.printStackTrace();
- }
- if (bitmap != null) {
- ImageView cover = view.findViewById(R.id.cd_image);
- cover.setImageBitmap(bitmap);
- }
- view.invalidate();
- return view;
- }
Add Comment
Please, Sign In to add comment