我想在我的应用程序中播放播放列表名称为“myPlaylist”的歌曲我在我的应用程序中搜索我播放所选播放列表的歌曲我们可以通过ID选择播放列表我在GenyMotion中传递了3个播放列表
PlaySongsFromAPlaylist(0);
第一个播放列表的0 我的方法是
public void PlaySongsFromAPlaylist(int playListID){
String[] ARG_STRING = {MediaStore.Audio.Media._ID,MediaStore.Audio.Media.DATA,MediaStore.Audio.Media.DISPLAY_NAME,MediaStore.Video.Media.SIZE,android.provider.MediaStore.MediaColumns.DATA};
Uri membersUri= MediaStore.Audio.Playlists.Members.getContentUri("external", playListID);
Cursor songsWithingAPlayList = this.managedQuery(membersUri, ARG_STRING, null, null, null);
int theSongIDIwantToPlay = 0; // PLAYING FROM THE FIRST SONG
if(songsWithingAPlayList != null)
{
songsWithingAPlayList.moveToPosition(theSongIDIwantToPlay);
String DataStream = songsWithingAPlayList.getString(4);
PlayMusic(DataStream);
songsWithingAPlayList.close();
}
}
但我发现错误
java.lang.RuntimeException:无法启动活动ComponentInfo {com.xample.playfromplaylist / com.xample.playfromplaylist.MainActivity}:android.database.CursorIndexOutOfBoundsException:请求索引0,大小为0
任何人都可以帮忙解决问题?