android.provider.MediaStore.Audio.Albums Java Examples

The following examples show how to use android.provider.MediaStore.Audio.Albums. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AlbumHelper.java    From sctalk with Apache License 2.0 6 votes vote down vote up
/**
 * @Description 得到原图
 */
@SuppressWarnings("unused")
private void getAlbum() {
    String[] projection = {
            Albums._ID, Albums.ALBUM, Albums.ALBUM_ART,
            Albums.ALBUM_KEY, Albums.ARTIST, Albums.NUMBER_OF_SONGS
    };
    Cursor cursor = null;
    try {
        cursor = contentResolver.query(Albums.EXTERNAL_CONTENT_URI,
                projection, null, null, null);
        getAlbumColumnData(cursor);
    } catch (Exception e) {
        logger.e(e.getMessage());
    } finally {
        if (null != cursor) {
            cursor.close();
        }
    }

}
 
Example #2
Source File: AlbumHelper.java    From sctalk with Apache License 2.0 5 votes vote down vote up
/**
 * 从数据库中得到原图
 * 
 * @param cur
 */
private void getAlbumColumnData(Cursor cur) {
    try {
        if (cur.moveToFirst()) {
            int _id;
            String album;
            String albumArt;
            String albumKey;
            String artist;
            int numOfSongs;

            int _idColumn = cur.getColumnIndex(Albums._ID);
            int albumColumn = cur.getColumnIndex(Albums.ALBUM);
            int albumArtColumn = cur.getColumnIndex(Albums.ALBUM_ART);
            int albumKeyColumn = cur.getColumnIndex(Albums.ALBUM_KEY);
            int artistColumn = cur.getColumnIndex(Albums.ARTIST);
            int numOfSongsColumn = cur.getColumnIndex(Albums.NUMBER_OF_SONGS);

            do {
                _id = cur.getInt(_idColumn);
                album = cur.getString(albumColumn);
                albumArt = cur.getString(albumArtColumn);
                albumKey = cur.getString(albumKeyColumn);
                artist = cur.getString(artistColumn);
                numOfSongs = cur.getInt(numOfSongsColumn);
                HashMap<String, String> hash = new HashMap<String, String>();
                hash.put("_id", _id + "");
                hash.put("album", album);
                hash.put("albumArt", albumArt);
                hash.put("albumKey", albumKey);
                hash.put("artist", artist);
                hash.put("numOfSongs", numOfSongs + "");
                albumList.add(hash);
            } while (cur.moveToNext());

        }
    } catch (Exception e) {
        logger.e(e.getMessage());
    }
}
 
Example #3
Source File: AlbumHelper.java    From quickmark with MIT License 5 votes vote down vote up
/**
 * �õ�ԭͼ
 */
void getAlbum() {
	String[] projection = { Albums._ID, Albums.ALBUM, Albums.ALBUM_ART,
			Albums.ALBUM_KEY, Albums.ARTIST, Albums.NUMBER_OF_SONGS };
	Cursor cursor = cr.query(Albums.EXTERNAL_CONTENT_URI, projection, null,
			null, null);
	getAlbumColumnData(cursor);

}
 
Example #4
Source File: AlbumHelper.java    From school_shop with MIT License 5 votes vote down vote up
void getAlbum() {
	String[] projection = { Albums._ID, Albums.ALBUM, Albums.ALBUM_ART,
			Albums.ALBUM_KEY, Albums.ARTIST, Albums.NUMBER_OF_SONGS };
	Cursor cursor = cr.query(Albums.EXTERNAL_CONTENT_URI, projection, null,
			null, null);
	getAlbumColumnData(cursor);

}
 
Example #5
Source File: MediaArtistsView.java    From AlarmOn with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  super.onItemClick(parent, view, position, id);
  albumsView.query(Albums.EXTERNAL_CONTENT_URI, ArtistColumns.ARTIST_KEY + " = '" + getLastSelectedName() + "'");
  getFlipper().setInAnimation(getContext(), R.anim.slide_in_left);
  getFlipper().setOutAnimation(getContext(), R.anim.slide_out_left);
  getFlipper().showNext();
}
 
Example #6
Source File: AlbumHelper.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 得到原图
 */
void getAlbum() {
	String[] projection = { Albums._ID, Albums.ALBUM, Albums.ALBUM_ART,
			Albums.ALBUM_KEY, Albums.ARTIST, Albums.NUMBER_OF_SONGS };
	Cursor cursor = cr.query(Albums.EXTERNAL_CONTENT_URI, projection, null,
			null, null);
	getAlbumColumnData(cursor);

}
 
Example #7
Source File: UEImageManager.java    From Auie with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 创建图片原图集合
 */
private void createAlbums(){
	Cursor cursor = mContentResolver.query(Media.EXTERNAL_CONTENT_URI, ALBUMS_PROJECTION, null, null, null);
	if (cursor.moveToFirst()) {
		int idIndex = cursor.getColumnIndex(Albums._ID);
		int albumIndex  = cursor.getColumnIndex(Albums.ALBUM);
		int albumArtIndex  = cursor.getColumnIndex(Albums.ALBUM_ART);
		int albumKeyIndex  = cursor.getColumnIndex(Albums.ALBUM_KEY);
		int artistIndex  = cursor.getColumnIndex(Albums.ARTIST);
		int numberOfSongsIndex  = cursor.getColumnIndex(Albums.NUMBER_OF_SONGS);
		do {
			int id = cursor.getInt(idIndex);
			int numberOfSongs = cursor.getInt(numberOfSongsIndex);
			String album = cursor.getString(albumIndex);
			String artist = cursor.getString(artistIndex);
			String albumKey = cursor.getString(albumKeyIndex);
			String albumArt = cursor.getString(albumArtIndex);
			Map<String, String> albumItem = new HashMap<String, String>();
			albumItem.put("_id", String.valueOf(id));
			albumItem.put("album", album);
			albumItem.put("albumArt", albumArt);
			albumItem.put("albumKey", albumKey);
			albumItem.put("artist", artist);
			albumItem.put("numOfSongs", String.valueOf(numberOfSongs));
			albums.add(albumItem);
		} while (cursor.moveToNext());
	}
	cursor.close();
}
 
Example #8
Source File: MediaDocumentsProvider.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
@Override
public Cursor queryDocument(String docId, String[] projection) throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    final Ident ident = getIdentForDocId(docId);

    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        if (TYPE_IMAGES_ROOT.equals(ident.type)) {
            // single root
            includeImagesRootDocument(result);
        } else if (TYPE_IMAGES_BUCKET.equals(ident.type)) {
            // single bucket
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                    ImagesBucketQuery.PROJECTION, ImageColumns.BUCKET_ID + "=" + ident.id,
                    null, ImagesBucketQuery.SORT_ORDER);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeImagesBucket(result, cursor);
            }
        } else if (TYPE_IMAGE.equals(ident.type)) {
            // single image
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                    ImageQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeImage(result, cursor);
            }
        } else if (TYPE_VIDEOS_ROOT.equals(ident.type)) {
            // single root
            includeVideosRootDocument(result);
        } else if (TYPE_VIDEOS_BUCKET.equals(ident.type)) {
            // single bucket
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI,
                    VideosBucketQuery.PROJECTION, VideoColumns.BUCKET_ID + "=" + ident.id,
                    null, VideosBucketQuery.SORT_ORDER);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeVideosBucket(result, cursor);
            }
        } else if (TYPE_VIDEO.equals(ident.type)) {
            // single video
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI,
                    VideoQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Video.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeVideo(result, cursor);
            }
        } else if (TYPE_AUDIO_ROOT.equals(ident.type)) {
            // single root
            includeAudioRootDocument(result);
        } else if (TYPE_ARTIST.equals(ident.type)) {
            // single artist
            cursor = resolver.query(Artists.EXTERNAL_CONTENT_URI,
                    ArtistQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Artists.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeArtist(result, cursor);
            }
        } else if (TYPE_ALBUM.equals(ident.type)) {
            // single album
            cursor = resolver.query(Albums.EXTERNAL_CONTENT_URI,
                    AlbumQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Albums.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeAlbum(result, cursor);
            }
        } else if (TYPE_AUDIO.equals(ident.type)) {
            // single song
            cursor = resolver.query(Audio.Media.EXTERNAL_CONTENT_URI,
                    SongQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Audio.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeAudio(result, cursor);
            }
        } else {
            throw new UnsupportedOperationException("Unsupported document " + docId);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
 
Example #9
Source File: MediaDocumentsProvider.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
@Override
public Cursor queryDocument(String docId, String[] projection) throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    final Ident ident = getIdentForDocId(docId);

    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        if (TYPE_IMAGES_ROOT.equals(ident.type)) {
            // single root
            includeImagesRootDocument(result);
        } else if (TYPE_IMAGES_BUCKET.equals(ident.type)) {
            // single bucket
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                    ImagesBucketQuery.PROJECTION, ImageColumns.BUCKET_ID + "=" + ident.id,
                    null, ImagesBucketQuery.SORT_ORDER);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeImagesBucket(result, cursor);
            }
        } else if (TYPE_IMAGE.equals(ident.type)) {
            // single image
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                    ImageQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeImage(result, cursor);
            }
        } else if (TYPE_VIDEOS_ROOT.equals(ident.type)) {
            // single root
            includeVideosRootDocument(result);
        } else if (TYPE_VIDEOS_BUCKET.equals(ident.type)) {
            // single bucket
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI,
                    VideosBucketQuery.PROJECTION, VideoColumns.BUCKET_ID + "=" + ident.id,
                    null, VideosBucketQuery.SORT_ORDER);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeVideosBucket(result, cursor);
            }
        } else if (TYPE_VIDEO.equals(ident.type)) {
            // single video
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI,
                    VideoQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Video.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeVideo(result, cursor);
            }
        } else if (TYPE_AUDIO_ROOT.equals(ident.type)) {
            // single root
            includeAudioRootDocument(result);
        } else if (TYPE_ARTIST.equals(ident.type)) {
            // single artist
            cursor = resolver.query(Artists.EXTERNAL_CONTENT_URI,
                    ArtistQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Artists.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeArtist(result, cursor);
            }
        } else if (TYPE_ALBUM.equals(ident.type)) {
            // single album
            cursor = resolver.query(Albums.EXTERNAL_CONTENT_URI,
                    AlbumQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Albums.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeAlbum(result, cursor);
            }
        } else if (TYPE_AUDIO.equals(ident.type)) {
            // single song
            cursor = resolver.query(Audio.Media.EXTERNAL_CONTENT_URI,
                    SongQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Audio.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeAudio(result, cursor);
            }
        } else {
            throw new UnsupportedOperationException("Unsupported document " + docId);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
 
Example #10
Source File: MediaDocumentsProvider.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
@Override
public Cursor queryDocument(String docId, String[] projection) throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    final Ident ident = getIdentForDocId(docId);

    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        if (TYPE_IMAGES_ROOT.equals(ident.type)) {
            // single root
            includeImagesRootDocument(result);
        } else if (TYPE_IMAGES_BUCKET.equals(ident.type)) {
            // single bucket
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                    ImagesBucketQuery.PROJECTION, ImageColumns.BUCKET_ID + "=" + ident.id,
                    null, ImagesBucketQuery.SORT_ORDER);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeImagesBucket(result, cursor);
            }
        } else if (TYPE_IMAGE.equals(ident.type)) {
            // single image
            cursor = resolver.query(Images.Media.EXTERNAL_CONTENT_URI,
                    ImageQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeImage(result, cursor);
            }
        } else if (TYPE_VIDEOS_ROOT.equals(ident.type)) {
            // single root
            includeVideosRootDocument(result);
        } else if (TYPE_VIDEOS_BUCKET.equals(ident.type)) {
            // single bucket
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI,
                    VideosBucketQuery.PROJECTION, VideoColumns.BUCKET_ID + "=" + ident.id,
                    null, VideosBucketQuery.SORT_ORDER);
            copyNotificationUri(result, Images.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeVideosBucket(result, cursor);
            }
        } else if (TYPE_VIDEO.equals(ident.type)) {
            // single video
            cursor = resolver.query(Video.Media.EXTERNAL_CONTENT_URI,
                    VideoQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Video.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeVideo(result, cursor);
            }
        } else if (TYPE_AUDIO_ROOT.equals(ident.type)) {
            // single root
            includeAudioRootDocument(result);
        } else if (TYPE_ARTIST.equals(ident.type)) {
            // single artist
            cursor = resolver.query(Artists.EXTERNAL_CONTENT_URI,
                    ArtistQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Artists.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeArtist(result, cursor);
            }
        } else if (TYPE_ALBUM.equals(ident.type)) {
            // single album
            cursor = resolver.query(Albums.EXTERNAL_CONTENT_URI,
                    AlbumQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Albums.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeAlbum(result, cursor);
            }
        } else if (TYPE_AUDIO.equals(ident.type)) {
            // single song
            cursor = resolver.query(Audio.Media.EXTERNAL_CONTENT_URI,
                    SongQuery.PROJECTION, BaseColumns._ID + "=" + ident.id, null,
                    null);
            copyNotificationUri(result, Audio.Media.EXTERNAL_CONTENT_URI);
            if (cursor.moveToFirst()) {
                includeAudio(result, cursor);
            }
        } else {
            throw new UnsupportedOperationException("Unsupported document " + docId);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
 
Example #11
Source File: AlbumHelper.java    From quickmark with MIT License 4 votes vote down vote up
/**
 * �ӱ������ݿ��еõ�ԭͼ
 * 
 * @param cur
 */
private void getAlbumColumnData(Cursor cur) {
	if (cur.moveToFirst()) {
		int _id;
		String album;
		String albumArt;
		String albumKey;
		String artist;
		int numOfSongs;

		int _idColumn = cur.getColumnIndex(Albums._ID);
		int albumColumn = cur.getColumnIndex(Albums.ALBUM);
		int albumArtColumn = cur.getColumnIndex(Albums.ALBUM_ART);
		int albumKeyColumn = cur.getColumnIndex(Albums.ALBUM_KEY);
		int artistColumn = cur.getColumnIndex(Albums.ARTIST);
		int numOfSongsColumn = cur.getColumnIndex(Albums.NUMBER_OF_SONGS);

		do {
			// Get the field values
			_id = cur.getInt(_idColumn);
			album = cur.getString(albumColumn);
			albumArt = cur.getString(albumArtColumn);
			albumKey = cur.getString(albumKeyColumn);
			artist = cur.getString(artistColumn);
			numOfSongs = cur.getInt(numOfSongsColumn);

			// Do something with the values.
			Log.i(TAG, _id + " album:" + album + " albumArt:" + albumArt
					+ "albumKey: " + albumKey + " artist: " + artist
					+ " numOfSongs: " + numOfSongs + "---");
			HashMap<String, String> hash = new HashMap<String, String>();
			hash.put("_id", _id + "");
			hash.put("album", album);
			hash.put("albumArt", albumArt);
			hash.put("albumKey", albumKey);
			hash.put("artist", artist);
			hash.put("numOfSongs", numOfSongs + "");
			albumList.add(hash);

		} while (cur.moveToNext());

	}
}
 
Example #12
Source File: AlbumHelper.java    From school_shop with MIT License 4 votes vote down vote up
private void getAlbumColumnData(Cursor cur) {
	if (cur.moveToFirst()) {
		int _id;
		String album;
		String albumArt;
		String albumKey;
		String artist;
		int numOfSongs;

		int _idColumn = cur.getColumnIndex(Albums._ID);
		int albumColumn = cur.getColumnIndex(Albums.ALBUM);
		int albumArtColumn = cur.getColumnIndex(Albums.ALBUM_ART);
		int albumKeyColumn = cur.getColumnIndex(Albums.ALBUM_KEY);
		int artistColumn = cur.getColumnIndex(Albums.ARTIST);
		int numOfSongsColumn = cur.getColumnIndex(Albums.NUMBER_OF_SONGS);

		do {
			// Get the field values
			_id = cur.getInt(_idColumn);
			album = cur.getString(albumColumn);
			albumArt = cur.getString(albumArtColumn);
			albumKey = cur.getString(albumKeyColumn);
			artist = cur.getString(artistColumn);
			numOfSongs = cur.getInt(numOfSongsColumn);

			// Do something with the values.
			Log.i(TAG, _id + " album:" + album + " albumArt:" + albumArt
					+ "albumKey: " + albumKey + " artist: " + artist
					+ " numOfSongs: " + numOfSongs + "---");
			HashMap<String, String> hash = new HashMap<String, String>();
			hash.put("_id", _id + "");
			hash.put("album", album);
			hash.put("albumArt", albumArt);
			hash.put("albumKey", albumKey);
			hash.put("artist", artist);
			hash.put("numOfSongs", numOfSongs + "");
			albumList.add(hash);

		} while (cur.moveToNext());

	}
}
 
Example #13
Source File: AlbumHelper.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
/**
 * 从本地数据库中得到原图
 * 
 * @param cur
 */
private void getAlbumColumnData(Cursor cur) {
	if (cur.moveToFirst()) {
		int _id;
		String album;
		String albumArt;
		String albumKey;
		String artist;
		int numOfSongs;

		int _idColumn = cur.getColumnIndex(Albums._ID);
		int albumColumn = cur.getColumnIndex(Albums.ALBUM);
		int albumArtColumn = cur.getColumnIndex(Albums.ALBUM_ART);
		int albumKeyColumn = cur.getColumnIndex(Albums.ALBUM_KEY);
		int artistColumn = cur.getColumnIndex(Albums.ARTIST);
		int numOfSongsColumn = cur.getColumnIndex(Albums.NUMBER_OF_SONGS);

		do {
			// Get the field values
			_id = cur.getInt(_idColumn);
			album = cur.getString(albumColumn);
			albumArt = cur.getString(albumArtColumn);
			albumKey = cur.getString(albumKeyColumn);
			artist = cur.getString(artistColumn);
			numOfSongs = cur.getInt(numOfSongsColumn);

			// Do something with the values.
			Log.i(TAG, _id + " album:" + album + " albumArt:" + albumArt
					+ "albumKey: " + albumKey + " artist: " + artist
					+ " numOfSongs: " + numOfSongs + "---");
			HashMap<String, String> hash = new HashMap<String, String>();
			hash.put("_id", _id + "");
			hash.put("album", album);
			hash.put("albumArt", albumArt);
			hash.put("albumKey", albumKey);
			hash.put("artist", artist);
			hash.put("numOfSongs", numOfSongs + "");
			albumList.add(hash);

		} while (cur.moveToNext());

	}
}