本文整理汇总了Java中android.provider.MediaStore.Audio.AudioColumns类的典型用法代码示例。如果您正苦于以下问题:Java AudioColumns类的具体用法?Java AudioColumns怎么用?Java AudioColumns使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AudioColumns类属于android.provider.MediaStore.Audio包,在下文中一共展示了AudioColumns类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makePlaylistSongCursor
import android.provider.MediaStore.Audio.AudioColumns; //导入依赖的package包/类
public static Cursor makePlaylistSongCursor(@NonNull final Context context, final int playlistId) {
try {
return context.getContentResolver().query(
MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId),
new String[]{
MediaStore.Audio.Playlists.Members.AUDIO_ID,// 0
AudioColumns.TITLE,// 1
AudioColumns.TRACK,// 2
AudioColumns.YEAR,// 3
AudioColumns.DURATION,// 4
AudioColumns.DATA,// 5
AudioColumns.DATE_MODIFIED,// 6
AudioColumns.ALBUM_ID,// 7
AudioColumns.ALBUM,// 8
AudioColumns.ARTIST_ID,// 9
AudioColumns.ARTIST,// 10
MediaStore.Audio.Playlists.Members._ID // 11
}, SongLoader.BASE_SELECTION, null,
MediaStore.Audio.Playlists.Members.DEFAULT_SORT_ORDER);
} catch (SecurityException e) {
return null;
}
}
示例2: makeLastAddedCursor
import android.provider.MediaStore.Audio.AudioColumns; //导入依赖的package包/类
public static final Cursor makeLastAddedCursor(final Context context) {
//four weeks ago
long fourWeeksAgo = (System.currentTimeMillis() / 1000) - (4 * 3600 * 24 * 7);
long cutoff = PreferencesUtility.getInstance(context).getLastAddedCutoff();
// use the most recent of the two timestamps
if (cutoff < fourWeeksAgo) {
cutoff = fourWeeksAgo;
}
final StringBuilder selection = new StringBuilder();
selection.append(AudioColumns.IS_MUSIC + "=1");
selection.append(" AND " + AudioColumns.TITLE + " != ''");
selection.append(" AND " + MediaStore.Audio.Media.DATE_ADDED + ">");
selection.append(cutoff);
return context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String[]{"_id", "title", "artist", "album", "duration", "track", "artist_id", "album_id"}, selection.toString(), null, MediaStore.Audio.Media.DATE_ADDED + " DESC");
}
示例3: makePlaylistSongCursor
import android.provider.MediaStore.Audio.AudioColumns; //导入依赖的package包/类
public static final Cursor makePlaylistSongCursor(final Context context, final Long playlistID) {
final StringBuilder mSelection = new StringBuilder();
mSelection.append(AudioColumns.IS_MUSIC + "=1");
mSelection.append(" AND " + AudioColumns.TITLE + " != ''");
return context.getContentResolver().query(
MediaStore.Audio.Playlists.Members.getContentUri("external", playlistID),
new String[]{
MediaStore.Audio.Playlists.Members._ID,
MediaStore.Audio.Playlists.Members.AUDIO_ID,
AudioColumns.TITLE,
AudioColumns.ARTIST,
AudioColumns.ALBUM_ID,
AudioColumns.ARTIST_ID,
AudioColumns.ALBUM,
AudioColumns.DURATION,
AudioColumns.TRACK,
Playlists.Members.PLAY_ORDER,
}, mSelection.toString(), null,
MediaStore.Audio.Playlists.Members.DEFAULT_SORT_ORDER);
}
示例4: getSongListForArtist
import android.provider.MediaStore.Audio.AudioColumns; //导入依赖的package包/类
/**
* @param context The {@link Context} to use.
* @param id The ID of the artist.
* @return The song list for an artist.
*/
public static final long[] getSongListForArtist(final Context context, final long id) {
final String[] projection = new String[]{
BaseColumns._ID
};
final String selection = AudioColumns.ARTIST_ID + "=" + id + " AND "
+ AudioColumns.IS_MUSIC + "=1";
Cursor cursor = context.getContentResolver().query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection, null,
AudioColumns.ALBUM_KEY + "," + AudioColumns.TRACK);
if (cursor != null) {
final long[] mList = getSongListForCursor(cursor);
cursor.close();
cursor = null;
return mList;
}
return sEmptyList;
}
示例5: getSongListForAlbum
import android.provider.MediaStore.Audio.AudioColumns; //导入依赖的package包/类
/**
* @param context The {@link Context} to use.
* @param id The ID of the album.
* @return The song list for an album.
*/
public static final long[] getSongListForAlbum(final Context context, final long id) {
final String[] projection = new String[]{
BaseColumns._ID
};
final String selection = AudioColumns.ALBUM_ID + "=" + id + " AND " + AudioColumns.IS_MUSIC
+ "=1";
Cursor cursor = context.getContentResolver().query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection, null,
AudioColumns.TRACK + ", " + MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
if (cursor != null) {
final long[] mList = getSongListForCursor(cursor);
cursor.close();
cursor = null;
return mList;
}
return sEmptyList;
}
示例6: getSongListForGenre
import android.provider.MediaStore.Audio.AudioColumns; //导入依赖的package包/类
/**
* @param context The {@link Context} to use.
* @param id The ID of the genre.
* @return The song list for an genre.
*/
public static final long[] getSongListForGenre(final Context context, final long id) {
final String[] projection = new String[]{
BaseColumns._ID
};
String selection = (AudioColumns.IS_MUSIC + "=1") +
" AND " + MediaColumns.TITLE + "!=''";
final Uri uri = MediaStore.Audio.Genres.Members.getContentUri("external", Long.valueOf(id));
Cursor cursor = context.getContentResolver().query(uri, projection, selection,
null, null);
if (cursor != null) {
final long[] mList = getSongListForCursor(cursor);
cursor.close();
cursor = null;
return mList;
}
return sEmptyList;
}
示例7: makeGenreSongCursor
import android.provider.MediaStore.Audio.AudioColumns; //导入依赖的package包/类
private static Cursor makeGenreSongCursor(Context context, long genreId) {
try {
return context.getContentResolver().query(
MediaStore.Audio.Genres.Members.getContentUri("external", genreId),
new String[]{
MediaStore.Audio.Playlists.Members.AUDIO_ID,// 0
AudioColumns.TITLE,// 1
AudioColumns.TRACK,// 2
AudioColumns.YEAR,// 3
AudioColumns.DURATION,// 4
AudioColumns.DATA,// 5
AudioColumns.DATE_MODIFIED,// 6
AudioColumns.ALBUM_ID,// 7
AudioColumns.ALBUM,// 8
AudioColumns.ARTIST_ID,// 9
AudioColumns.ARTIST,// 10
}, SongLoader.BASE_SELECTION, null,
MediaStore.Audio.Genres.Members.DEFAULT_SORT_ORDER);
} catch (SecurityException e) {
return null;
}
}
示例8: makeLastAddedCursor
import android.provider.MediaStore.Audio.AudioColumns; //导入依赖的package包/类
public static final Cursor makeLastAddedCursor(final Context context) {
//four weeks ago
long fourWeeksAgo = (System.currentTimeMillis() / 1000) - (4 * 3600 * 24 * 7);
long cutoff = 0L;
// use the most recent of the two timestamps
if (cutoff < fourWeeksAgo) {
cutoff = fourWeeksAgo;
}
final StringBuilder selection = new StringBuilder();
selection.append(AudioColumns.IS_MUSIC + "=1");
selection.append(" AND " + AudioColumns.TITLE + " != ''");
selection.append(" AND " + MediaStore.Audio.Media.DATE_ADDED + ">");
selection.append(cutoff);
return context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String[]{"_id", "title", "artist", "album", "duration", "track", "artist_id", "album_id"}, selection.toString(), null, MediaStore.Audio.Media.DATE_ADDED + " DESC");
}
示例9: getMp3List
import android.provider.MediaStore.Audio.AudioColumns; //导入依赖的package包/类
public static List<Playlist> getMp3List(Context context) {
List<Playlist> list = new ArrayList<Playlist>();
Cursor cursor = new ResolverSer().getResolverSer().getResover(context).query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, media_info, "",
null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
if (cursor != null && cursor.getCount() == 0) {
final AlertDialog xfdialog = new AlertDialog.Builder(context).setTitle("Tips:").setMessage(context.getResources().getString(R.string.music_no_one)).setPositiveButton(context.getResources().getString(R.string.is_positive), null).create();
xfdialog.show();
cursor.close();
return null;
}
while (cursor.moveToNext()) {
int id = cursor.getInt(cursor.getColumnIndex(BaseColumns._ID));
int album_id = cursor.getInt(cursor.getColumnIndex(AudioColumns.ALBUM_ID));
String title = cursor.getString(cursor.getColumnIndex(MediaColumns.TITLE));
String artist = cursor.getString(cursor.getColumnIndex(AudioColumns.ARTIST));
int duration = cursor.getInt(cursor.getColumnIndex(AudioColumns.DURATION));
if (duration > 30000) {
Playlist playlist = new Playlist(id, title, duration, artist, album_id);
list.add(playlist);
}
}
cursor.close();
return list;
}
示例10: makeAutoShuffleList
import android.provider.MediaStore.Audio.AudioColumns; //导入依赖的package包/类
private boolean makeAutoShuffleList() {
ContentResolver res = getContentResolver();
Cursor c = null;
try {
c = res.query(Audio.Media.EXTERNAL_CONTENT_URI, new String[] {
BaseColumns._ID
}, AudioColumns.IS_MUSIC + "=1", null, null);
if (c == null || c.getCount() == 0) {
return false;
}
int len = c.getCount();
long[] list = new long[len];
for (int i = 0; i < len; i++) {
c.moveToNext();
list[i] = c.getLong(0);
}
mAutoShuffleList = list;
return true;
} catch (RuntimeException ex) {
} finally {
if (c != null) {
c.close();
}
}
return false;
}
示例11: onCreateLoader
import android.provider.MediaStore.Audio.AudioColumns; //导入依赖的package包/类
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
String[] projection = new String[] {
BaseColumns._ID, MediaColumns.TITLE, AudioColumns.ALBUM, AudioColumns.ARTIST,
};
StringBuilder selection = new StringBuilder();
Uri uri = Audio.Media.EXTERNAL_CONTENT_URI;
String sortOrder = Audio.Media.DEFAULT_SORT_ORDER;
uri = Audio.Media.EXTERNAL_CONTENT_URI;
long[] mNowPlaying = MusicUtils.getQueue();
if (mNowPlaying.length == 0)
return null;
selection = new StringBuilder();
selection.append(BaseColumns._ID + " IN (");
if (mNowPlaying == null || mNowPlaying.length <= 0)
return null;
for (long queue_id : mNowPlaying) {
selection.append(queue_id + ",");
}
selection.deleteCharAt(selection.length() - 1);
selection.append(")");
return new AddIdCursorLoader(getActivity(), uri, projection, selection.toString(), null,
sortOrder);
}
示例12: reloadQueueCursor
import android.provider.MediaStore.Audio.AudioColumns; //导入依赖的package包/类
/**
* Reload the queue after we remove a track
*/
private void reloadQueueCursor() {
String[] projection = new String[] {
BaseColumns._ID, MediaColumns.TITLE, AudioColumns.ALBUM, AudioColumns.ARTIST,
};
StringBuilder selection = new StringBuilder();
Uri uri = Audio.Media.EXTERNAL_CONTENT_URI;
String sortOrder = Audio.Media.DEFAULT_SORT_ORDER;
uri = Audio.Media.EXTERNAL_CONTENT_URI;
long[] mNowPlaying = MusicUtils.getQueue();
if (mNowPlaying.length == 0)
return;
selection = new StringBuilder();
selection.append(BaseColumns._ID + " IN (");
if (mNowPlaying == null || mNowPlaying.length <= 0)
return;
for (long queue_id : mNowPlaying) {
selection.append(queue_id + ",");
}
selection.deleteCharAt(selection.length() - 1);
selection.append(")");
mCursor = MusicUtils.query(getActivity(), uri, projection, selection.toString(), null,
sortOrder);
mQuickQueueAdapter.changeCursor(mCursor);
}
示例13: setupFragmentData
import android.provider.MediaStore.Audio.AudioColumns; //导入依赖的package包/类
@Override
public void setupFragmentData() {
mAdapter = new AlbumListAdapter(getActivity(), R.layout.music_listview_items, null,
new String[] {}, new int[] {}, 0);
mProjection = new String[] {
BaseColumns._ID, MediaColumns.TITLE, AudioColumns.ALBUM, AudioColumns.ARTIST
};
StringBuilder where = new StringBuilder();
where.append(AudioColumns.IS_MUSIC + "=1")
.append(" AND " + MediaColumns.TITLE + " != ''");
long albumId = getArguments().getLong(BaseColumns._ID);
where.append(" AND " + AudioColumns.ALBUM_ID + "=" + albumId);
mWhere = where.toString();
mSortOrder = Audio.Media.TRACK + ", " + Audio.Media.DEFAULT_SORT_ORDER;
mUri = Audio.Media.EXTERNAL_CONTENT_URI;
mFragmentGroupId = 89;
mType = TYPE_ALBUM;
mTitleColumn = MediaColumns.TITLE;
}
示例14: setupFragmentData
import android.provider.MediaStore.Audio.AudioColumns; //导入依赖的package包/类
public void setupFragmentData(){
mAdapter = new RecentlyAddedAdapter(getActivity(), R.layout.music_listview_items,
null, new String[] {}, new int[] {}, 0);
mProjection = new String[] {
BaseColumns._ID, MediaColumns.TITLE, AudioColumns.ALBUM, AudioColumns.ARTIST
};
StringBuilder where = new StringBuilder();
int X = MusicUtils.getIntPref(getActivity(), NUMWEEKS, 5) * 3600 * 24 * 7;
where.append(MediaColumns.TITLE + " != ''");
where.append(" AND " + AudioColumns.IS_MUSIC + "=1");
where.append(" AND " + MediaColumns.DATE_ADDED + ">"
+ (System.currentTimeMillis() / 1000 - X));
mWhere = where.toString();
mSortOrder = MediaColumns.DATE_ADDED + " DESC";
mUri = Audio.Media.EXTERNAL_CONTENT_URI;
mTitleColumn = MediaColumns.TITLE;
}
示例15: onLoadFinished
import android.provider.MediaStore.Audio.AudioColumns; //导入依赖的package包/类
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
if (data == null) {
return;
}
long[] mNowPlaying = MusicUtils.getQueue();
String[] audioCols = new String[] { BaseColumns._ID, MediaColumns.TITLE, AudioColumns.ARTIST, AudioColumns.ALBUM};
MatrixCursor playlistCursor = new MatrixCursor(audioCols);
for(int i = 0; i < mNowPlaying.length; i++){
data.moveToPosition(-1);
while (data.moveToNext()) {
long audioid = data.getLong(data.getColumnIndexOrThrow(BaseColumns._ID));
if( audioid == mNowPlaying[i]) {
String trackName = data.getString(data.getColumnIndexOrThrow(MediaColumns.TITLE));
String artistName = data.getString(data.getColumnIndexOrThrow(AudioColumns.ARTIST));
String albumName = data.getString(data.getColumnIndexOrThrow(AudioColumns.ALBUM));
playlistCursor.addRow(new Object[] {audioid, trackName, artistName, albumName });
}
}
}
data.close();
mCursor = playlistCursor;
super.onLoadFinished(loader, playlistCursor);
}