// Artist Album Item Retriever
  public ArrayList<ArtistAlbumItem> getArtistAlbumsList(ArtistItem ai) {
    Uri uri = MediaStore.Audio.Artists.Albums.getContentUri("external", ai.id);

    Cursor cur = mCR.query(uri, null, null, null, null);

    if (cur == null) {
      return null;
    }

    if (!cur.moveToFirst()) {
      return null;
    }

    ArrayList<ArtistAlbumItem> list = new ArrayList<ArtistAlbumItem>();

    int IDColumn = cur.getColumnIndex(MediaStore.Audio.Albums._ID);
    int albumColumn = cur.getColumnIndex(MediaStore.Audio.Albums.ALBUM);
    int tracksCountColumn = cur.getColumnIndex(MediaStore.Audio.Albums.NUMBER_OF_SONGS);
    int tracksByArtistCount =
        cur.getColumnIndex(MediaStore.Audio.Albums.NUMBER_OF_SONGS_FOR_ARTIST);

    do {
      list.add(
          new ArtistAlbumItem(
              cur.getLong(IDColumn),
              cur.getString(albumColumn),
              cur.getInt(tracksCountColumn),
              cur.getInt(tracksByArtistCount),
              ai));

    } while (cur.moveToNext());

    return list;
  }
Exemplo n.º 2
0
  public void testGetContentUri() {
    Cursor c = null;
    Uri contentUri =
        MediaStore.Audio.Artists.Albums.getContentUri(
            MediaStoreAudioTestHelper.INTERNAL_VOLUME_NAME, 1);
    assertNotNull(c = mContentResolver.query(contentUri, null, null, null, null));
    c.close();

    contentUri =
        MediaStore.Audio.Artists.Albums.getContentUri(
            MediaStoreAudioTestHelper.EXTERNAL_VOLUME_NAME, 1);
    assertNotNull(c = mContentResolver.query(contentUri, null, null, null, null));
    c.close();

    // can not accept any other volume names
    String volume = "fakeVolume";
    assertNull(
        mContentResolver.query(
            MediaStore.Audio.Artists.Albums.getContentUri(volume, 1), null, null, null, null));
  }
Exemplo n.º 3
0
  public static Cursor makeAlbumForArtistCursor(Context context, long artistID) {

    if (artistID == -1) return null;

    Cursor cursor =
        context
            .getContentResolver()
            .query(
                MediaStore.Audio.Artists.Albums.getContentUri("external", artistID),
                new String[] {"_id", "album", "artist", "numsongs", "minyear"},
                null,
                null,
                MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);

    return cursor;
  }
Exemplo n.º 4
0
  private void testStoreAudioArtistsAlbums(boolean isInternal) {
    // the album item is inserted when inserting audio media
    Uri audioMediaUri =
        isInternal
            ? Audio1.getInstance().insertToInternal(mContentResolver)
            : Audio1.getInstance().insertToExternal(mContentResolver);
    // get artist id
    Cursor c =
        mContentResolver.query(audioMediaUri, new String[] {Media.ARTIST_ID}, null, null, null);
    c.moveToFirst();
    Long artistId = c.getLong(c.getColumnIndex(Media.ARTIST_ID));
    c.close();
    Uri artistsAlbumsUri =
        MediaStore.Audio.Artists.Albums.getContentUri(
            isInternal
                ? MediaStoreAudioTestHelper.INTERNAL_VOLUME_NAME
                : MediaStoreAudioTestHelper.EXTERNAL_VOLUME_NAME,
            artistId);
    // do not support insert operation of the albums
    try {
      mContentResolver.insert(artistsAlbumsUri, new ContentValues());
      fail("Should throw UnsupportedOperationException!");
    } catch (UnsupportedOperationException e) {
      // expected
    }

    try {
      // query
      c = mContentResolver.query(artistsAlbumsUri, null, null, null, null);
      assertEquals(1, c.getCount());
      c.moveToFirst();

      assertEquals(Audio1.ALBUM, c.getString(c.getColumnIndex(Albums.ALBUM)));
      assertNull(c.getString(c.getColumnIndex(Albums.ALBUM_ART)));
      assertNotNull(c.getString(c.getColumnIndex(Albums.ALBUM_KEY)));
      assertEquals(Audio1.ARTIST, c.getString(c.getColumnIndex(Albums.ARTIST)));
      assertEquals(Audio1.YEAR, c.getInt(c.getColumnIndex(Albums.FIRST_YEAR)));
      assertEquals(Audio1.YEAR, c.getInt(c.getColumnIndex(Albums.LAST_YEAR)));
      assertEquals(1, c.getInt(c.getColumnIndex(Albums.NUMBER_OF_SONGS)));
      assertEquals(1, c.getInt(c.getColumnIndex(Albums.NUMBER_OF_SONGS_FOR_ARTIST)));
      // the ALBUM_ID column does not exist
      try {
        c.getColumnIndexOrThrow(Albums.ALBUM_ID);
        fail(
            "Should throw IllegalArgumentException because there is no column with name"
                + " \"Albums.ALBUM_ID\" in the table");
      } catch (IllegalArgumentException e) {
        // expected
      }
      c.close();

      // do not support update operation of the albums
      ContentValues albumValues = new ContentValues();
      albumValues.put(Albums.ALBUM, Audio2.ALBUM);
      try {
        mContentResolver.update(artistsAlbumsUri, albumValues, null, null);
        fail("Should throw UnsupportedOperationException!");
      } catch (UnsupportedOperationException e) {
        // expected
      }

      // do not support delete operation of the albums
      try {
        mContentResolver.delete(artistsAlbumsUri, null, null);
        fail("Should throw UnsupportedOperationException!");
      } catch (UnsupportedOperationException e) {
        // expected
      }
    } finally {
      mContentResolver.delete(audioMediaUri, null, null);
    }
    // the album items are deleted when deleting the audio media which belongs to the album
    c = mContentResolver.query(artistsAlbumsUri, null, null, null, null);
    assertEquals(0, c.getCount());
    c.close();
  }