Java 类android.provider.MediaStore.Audio.AudioColumns 实例源码

项目:Orin    文件:PlaylistSongLoader.java   
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;
    }
}
项目:Hello-Music-droid    文件:LastAddedLoader.java   
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");
}
项目:Hello-Music-droid    文件:PlaylistSongLoader.java   
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);
}
项目:KomaMusic    文件:MusicUtils.java   
/**
 * @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;
}
项目:KomaMusic    文件:MusicUtils.java   
/**
 * @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;
}
项目:KomaMusic    文件:MusicUtils.java   
/**
 * @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;
}
项目:RetroMusicPlayer    文件:PlaylistSongsLoader.java   
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;
    }
}
项目:RetroMusicPlayer    文件:GenreSongsLoader.java   
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;
    }
}
项目:Muzesto    文件:LastAddedLoader.java   
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");
}
项目:Muzesto    文件:PlaylistSongLoader.java   
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);
}
项目:LLApp    文件:MusicUtil.java   
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;
}
项目:mobile-manager-tool    文件:ApolloService.java   
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;
}
项目:mobile-manager-tool    文件:QuickQueueFragment.java   
@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);
}
项目:mobile-manager-tool    文件:QuickQueueFragment.java   
/**
 * 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);
}
项目:mobile-manager-tool    文件:AlbumListFragment.java   
@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; 
}
项目:mobile-manager-tool    文件:RecentlyAddedFragment.java   
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;       
}
项目:mobile-manager-tool    文件:NowPlayingFragment.java   
@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);
  }
项目:mobile-manager-tool    文件:GenreListFragment.java   
public void setupFragmentData(){
    mAdapter = new GenreListAdapter(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 + " != ''");
    mWhere = where.toString();        
    mSortOrder = Genres.Members.DEFAULT_SORT_ORDER;
    mUri = Genres.Members.getContentUri(EXTERNAL, getArguments().getLong(BaseColumns._ID));
    mFragmentGroupId = 3;
    mType = TYPE_GENRE;
    mTitleColumn = MediaColumns.TITLE; 
}
项目:mobile-manager-tool    文件:ArtistListFragment.java   
@Override
public void setupFragmentData(){
    mAdapter = new ArtistListAdapter(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 artist_id = getArguments().getLong(BaseColumns._ID);
    where.append(" AND " + AudioColumns.ARTIST_ID + "=" + artist_id);
    mWhere = where.toString();        
    mSortOrder = MediaColumns.TITLE;
    mUri = Audio.Media.EXTERNAL_CONTENT_URI;
    mFragmentGroupId = 88;
    mType = TYPE_ARTIST;
    mTitleColumn = MediaColumns.TITLE; 
}
项目:Phonograph    文件:PlaylistSongLoader.java   
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;
    }
}
项目:com.cp.monsterMod    文件:MusicUtils.java   
/**
 * @param context
 * @param id
 * @return
 */
public static long[] getSongListForArtist(Context context, long id) {
    final String[] projection = new String[] {
        BaseColumns._ID
    };
    String selection = AudioColumns.ARTIST_ID + "=" + id + " AND " + AudioColumns.IS_MUSIC
            + "=1";
    String sortOrder = AudioColumns.ALBUM_KEY + "," + AudioColumns.TRACK;
    Uri uri = Audio.Media.EXTERNAL_CONTENT_URI;
    Cursor cursor = query(context, uri, projection, selection, null, sortOrder);
    if (cursor != null) {
        long[] list = getSongListForCursor(cursor);
        cursor.close();
        return list;
    }
    return sEmptyList;
}
项目:com.cp.monsterMod    文件:MusicUtils.java   
/**
 * @param context
 * @param id
 * @return
 */
public static long[] getSongListForAlbum(Context context, long id) {
    final String[] projection = new String[] {
        BaseColumns._ID
    };
    String selection = AudioColumns.ALBUM_ID + "=" + id + " AND " + AudioColumns.IS_MUSIC
            + "=1";
    String sortOrder = AudioColumns.TRACK;
    Uri uri = Audio.Media.EXTERNAL_CONTENT_URI;
    Cursor cursor = query(context, uri, projection, selection, null, sortOrder);
    if (cursor != null) {
        long[] list = getSongListForCursor(cursor);
        cursor.close();
        return list;
    }
    return sEmptyList;
}
项目:com.cp.monsterMod    文件:MusicUtils.java   
/**
 * @param context
 * @param id
 * @return
 */
public static long[] getSongListForGenre(Context context, long id) {
    String[] projection = new String[] {
        BaseColumns._ID
    };
    StringBuilder selection = new StringBuilder();
    selection.append(AudioColumns.IS_MUSIC + "=1");
    selection.append(" AND " + MediaColumns.TITLE + "!=''");
    Uri uri = Genres.Members.getContentUri(EXTERNAL, id);
    Cursor cursor = context.getContentResolver().query(uri, projection, selection.toString(),
            null, null);
    if (cursor != null) {
        long[] list = getSongListForCursor(cursor);
        cursor.close();
        return list;
    }
    return sEmptyList;
}
项目:com.cp.monsterMod    文件:ApolloService.java   
private boolean makeAutoShuffleList() {
    ContentResolver res = getContentResolver();
    Cursor c = null;
    try {
        c = res.query(MediaStore.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;
}
项目:com.cp.monsterMod    文件:QuickQueueFragment.java   
@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);
}
项目:com.cp.monsterMod    文件:QuickQueueFragment.java   
/**
 * 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);
}
项目:com.cp.monsterMod    文件:AlbumListFragment.java   
@Override
public void setupFragmentData() {
       mAdapter = new AlbumListAdapter(getActivity(), R.layout.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; 
}
项目:com.cp.monsterMod    文件:RecentlyAddedFragment.java   
public void setupFragmentData(){
    mAdapter = new RecentlyAddedAdapter(getActivity(), R.layout.listview_items,
            null, new String[] {}, new int[] {}, 0);
    //构造查询语句,父类中回调,给cursorloader使用
    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";
    //查询音乐的uri?
    mUri = Audio.Media.EXTERNAL_CONTENT_URI;
    mTitleColumn = MediaColumns.TITLE;       
}
项目:com.cp.monsterMod    文件:NowPlayingFragment.java   
@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);
  }
项目:com.cp.monsterMod    文件:GenreListFragment.java   
public void setupFragmentData(){
    mAdapter = new GenreListAdapter(getActivity(), R.layout.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 + " != ''");
    mWhere = where.toString();        
    mSortOrder = Genres.Members.DEFAULT_SORT_ORDER;
    mUri = Genres.Members.getContentUri(EXTERNAL, getArguments().getLong(BaseColumns._ID));
    mFragmentGroupId = 3;
    mType = TYPE_GENRE;
    mTitleColumn = MediaColumns.TITLE; 
}
项目:com.cp.monsterMod    文件:ArtistListFragment.java   
@Override
public void setupFragmentData(){
    mAdapter = new ArtistListAdapter(getActivity(), R.layout.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 artist_id = getArguments().getLong(BaseColumns._ID);
    where.append(" AND " + AudioColumns.ARTIST_ID + "=" + artist_id);
    mWhere = where.toString();        
    mSortOrder = MediaColumns.TITLE;
    mUri = Audio.Media.EXTERNAL_CONTENT_URI;
    mFragmentGroupId = 88;
    mType = TYPE_ARTIST;
    mTitleColumn = MediaColumns.TITLE; 
}
项目:com.cp.monsterMod    文件:SongsFragment.java   
public void setupFragmentData(){
    mAdapter = new SonglistAdapter(getActivity(), R.layout.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 + " != ''");
    mWhere = where.toString();
    mSortOrder = Audio.Media.DEFAULT_SORT_ORDER;
    mUri = Audio.Media.EXTERNAL_CONTENT_URI;
    mFragmentGroupId = 3;
    mType = TYPE_SONG;
    mTitleColumn = MediaColumns.TITLE;         
    View shuffle_temp = View.inflate(getActivity(), R.layout.shuffle_all, null);
    mListView.addHeaderView(shuffle_temp);        
    RelativeLayout  shuffle = (RelativeLayout)shuffle_temp.findViewById(R.id.shuffle_wrapper);
    shuffle.setVisibility(View.VISIBLE);
    shuffle.setOnClickListener(new RelativeLayout.OnClickListener() {  
        public void onClick(View v)
        {
            MusicUtils.suffle(getActivity());
        }

     });
}
项目:itmarry    文件:MusicUtils.java   
/**
 * @param context
 * @param id
 * @return
 */
public static long[] getSongListForArtist(Context context, long id) {
    final String[] projection = new String[] {
        BaseColumns._ID
    };
    String selection = AudioColumns.ARTIST_ID + "=" + id + " AND " + AudioColumns.IS_MUSIC
            + "=1";
    String sortOrder = AudioColumns.ALBUM_KEY + "," + AudioColumns.TRACK;
    Uri uri = Audio.Media.EXTERNAL_CONTENT_URI;
    Cursor cursor = query(context, uri, projection, selection, null, sortOrder);
    if (cursor != null) {
        long[] list = getSongListForCursor(cursor);
        cursor.close();
        return list;
    }
    return sEmptyList;
}
项目:itmarry    文件:MusicUtils.java   
/**
 * @param context
 * @param id
 * @return
 */
public static long[] getSongListForAlbum(Context context, long id) {
    final String[] projection = new String[] {
        BaseColumns._ID
    };
    String selection = AudioColumns.ALBUM_ID + "=" + id + " AND " + AudioColumns.IS_MUSIC
            + "=1";
    String sortOrder = AudioColumns.TRACK;
    Uri uri = Audio.Media.EXTERNAL_CONTENT_URI;
    Cursor cursor = query(context, uri, projection, selection, null, sortOrder);
    if (cursor != null) {
        long[] list = getSongListForCursor(cursor);
        cursor.close();
        return list;
    }
    return sEmptyList;
}
项目:itmarry    文件:MusicUtils.java   
/**
 * @param context
 * @param id
 * @return
 */
public static long[] getSongListForGenre(Context context, long id) {
    String[] projection = new String[] {
        BaseColumns._ID
    };
    StringBuilder selection = new StringBuilder();
    selection.append(AudioColumns.IS_MUSIC + "=1");
    selection.append(" AND " + MediaColumns.TITLE + "!=''");
    Uri uri = Genres.Members.getContentUri(EXTERNAL, id);
    Cursor cursor = context.getContentResolver().query(uri, projection, selection.toString(),
            null, null);
    if (cursor != null) {
        long[] list = getSongListForCursor(cursor);
        cursor.close();
        return list;
    }
    return sEmptyList;
}
项目:itmarry    文件:ApolloService.java   
private boolean makeAutoShuffleList() {
    ContentResolver res = getContentResolver();
    Cursor c = null;
    try {
        c = res.query(MediaStore.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;
}
项目:itmarry    文件:QuickQueueFragment.java   
@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);
}
项目:itmarry    文件:QuickQueueFragment.java   
/**
 * 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);
}
项目:itmarry    文件:RecentlyAddedFragment.java   
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
     String[] projection = new String[] {
             BaseColumns._ID, MediaColumns.TITLE, AudioColumns.ALBUM, AudioColumns.ARTIST
     };
     StringBuilder where = new StringBuilder();
     String sortOrder = MediaColumns.DATE_ADDED + " DESC";
     Uri uri = Audio.Media.EXTERNAL_CONTENT_URI;
     int X = MusicUtils.getIntPref(getActivity(), NUMWEEKS, 5) * 3600 * 24 * 7;
     where = new StringBuilder();
     where.append(MediaColumns.TITLE + " != ''");
     where.append(" AND " + AudioColumns.IS_MUSIC + "=1");
     where.append(" AND " + MediaColumns.DATE_ADDED + ">"
             + (System.currentTimeMillis() / 1000 - X));
     return new AddIdCursorLoader(getActivity(), uri, projection, where.toString(), null, sortOrder);

    //return new RecentlyAddedLoader(getActivity());
}
项目:Player-by-TweekProject    文件:MusicUtils.java   
/**
 * @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 String 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;
}