2016-10-17 10 views
1

Android 기기에서 모든 노래 재생 목록을 검색하고 싶습니다. 나는 코드 샘플을 온라인으로 검색했지만 쿼리 playlistResolver.query (playlists, null, null, null, null)는 항상 나에게 크기 0을 준다. 재생 목록의 이름을 출력하는 do 루프는 결코 실행되지 않는다. 온라인에서 몇 가지 솔루션을 시도했지만 모두 작동하지 않았습니다. 어떤 도움을 주시면 감사하겠습니다. 감사!Android Media.Audio.Playlists는 항상 재생 목록을 반환하지 않습니다.

public void getSongList() { 
    //retrieve song info 
    ContentResolver musicResolver = getContentResolver(); 
    //retrieve playlists 
    ContentResolver playlistResolver = getApplicationContext().getContentResolver(); 

    Uri playlists = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI; 

    Cursor c = playlistResolver.query(playlists, null, null, null, null); 
    long playlistId = 0; 
    if(c!=null && c.moveToFirst()) { 
     do { 
      String plName = c.getString(c.getColumnIndex(MediaStore.Audio.Playlists.NAME)); 
      playlistId = c.getLong(c.getColumnIndex(MediaStore.Audio.Playlists._ID)); 
      Log.d("PLAYLIST NAME", "PLAYLIST NAME " + plName); 
     } while (c.moveToNext()); 
    } 
    c.close(); 

    Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; 

    String isMusic = MediaStore.Audio.Media.IS_MUSIC + "!= 0";//only get music tracks 
    Cursor musicCursor = musicResolver.query(musicUri, null, isMusic, null, null); 
    if(musicCursor!=null){ 
     musicCursor.moveToFirst(); 
     //get columns 
     int titleColumn = musicCursor.getColumnIndex 
       (android.provider.MediaStore.Audio.Media.TITLE); 
     int idColumn = musicCursor.getColumnIndex 
       (android.provider.MediaStore.Audio.Media._ID); 
     int artistColumn = musicCursor.getColumnIndex 
       (android.provider.MediaStore.Audio.Media.ARTIST); 
     int durationColumn = musicCursor.getColumnIndex 
       (MediaStore.Audio.AudioColumns.DURATION); 

     //add songs to list 
     do { 
      long thisId = musicCursor.getLong(idColumn); 
      String thisTitle = musicCursor.getString(titleColumn); 
      String thisArtist = musicCursor.getString(artistColumn); 
      int thisDuration = musicCursor.getInt(durationColumn); 
      //String thisPlaylist = musicCursor.getString(playlistColumn); 
      //Log.d("SONG IN PLAYLIST", "SONG " + thisTitle + " IN PLAYLIST " + thisPlaylist); 
      songList.add(new Song(thisId, thisTitle, thisArtist, thisDuration)); 
     } 
     while (musicCursor.moveToNext()); 
    } 
} 

답변

0

오늘 같은 문제가 발생했습니다. 재생 목록의 전체 저장 용량은 일반적으로 휴대 전화 \ 내부 저장 용량 \ 재생 목록입니다. 질문에서 인용 된 코드는 해당 글로벌 저장소에서만 재생 목록을 검색 할 수 있습니다. 음악 응용 프로그램이 로컬 저장소에 재생 목록을 만들면 해당 재생 목록에 액세스 할 수 없습니다.

나는 두 개의 서로 다른 음악 애플리케이션의 X를 설치하고 Y.

  • 모두를 재생 목록을 만들 수 있지만, 재생 목록 중 어느 것도 각 응용 프로그램이 자체로 만든 재생 목록을 표시 기본 저장 장소
  • 로 갈 것입니다. 어떤 앱도 에 다른 앱에서 만든 재생 목록이 표시되지 않았습니다.

그런 다음 세 번째 앱 Z를 설치했습니다. 전역 저장소에 재생 목록이 만들어졌으며 해당 질문의 코드를 사용하여 검색 할 수있었습니다. 첫 번째 앱 중 하나는 Z로 작성된 재생 목록을 표시 할 수 있었지만 로컬 저장소에서만 새로운 재생 목록을 계속 만들었습니다.