3
我已經在我的設備上預裝的「Music」應用程序中創建了3首歌曲的播放列表,並且在我自己的應用程序中已成功查詢MediaStore.Audio.Playlists。 EXTERNAL_CONTENT_URI(在調試中檢查名稱以確保它是正確的播放列表)並保存其ID,以便當我需要從其播放歌曲時。Android MediaStore播放列表返回錯誤軌跡
後來,當我播放其中一首歌曲時,播放列表中的歌曲數量正確,但播放列表中的歌曲會播放不同的曲目。以下是從播放列表中獲取曲目的代碼塊。
注意:這是在PhoneGap插件中,所以「this.ctx」是Activity。我的測試設備是運行Android 2.2的HTC Desire,如果這是相關的。
Cursor cursor = null;
Uri uri = null;
Log.d(TAG, "Selecting random song from playlist");
uri = Playlists.Members.getContentUri("external", this.currentPlaylistId);
if(uri == null) {
Log.e(TAG, "Encountered null Playlist Uri");
}
cursor = this.ctx.managedQuery(uri, new String[]{Playlists.Members._ID}, null, null, null);
if(cursor != null && cursor.getCount() > 0) {
this.numSongs = cursor.getCount();
Log.d(TAG, "numSongs: "+this.numSongs); // Correctly outputs 3
int randomNum = (int)(Math.random() * this.numSongs);
if(cursor.moveToPosition(randomNum)) {
int idColumn = cursor.getColumnIndex(Media._ID); // This doesn't seem to be giving me a track from the playlist
this.currentSongId = cursor.getLong(idColumn);
try {
JSONObject song = this.getSongInfo();
play(); // This plays whatever song id is in "this.currentSongId"
result = new PluginResult(Status.OK, song);
} catch (Exception e) {
result = new PluginResult(Status.ERROR);
}
}
}
謝謝,現在的作品治療。 – Liam984
@ Liam984這些ID很混亂:) – zapl