2011-11-23 87 views
1

我有一種方法,用戶每次點擊它都會轉到下一首歌曲。這個作品,直到獲得最後一個,然後我得到一個強制關閉,我想媒體播放器停止當它到達最後一個未關閉方法在Arraylist中跳過一個

ArrayList<String> nextSongname = nextsonginfo.getStringArrayList("nextsong"); 
ArrayList<String> nextArtistname = nextsonginfo.getStringArrayList("nextartist"); 
ArrayList<String> nextAlbumname = nextsonginfo.getStringArrayList("nextalbum"); 
ArrayList<String> nextPathname = nextsonginfo.getStringArrayList("nextpath"); 
ArrayList<String> artworkkeyword = nextsonginfo.getStringArrayList("nextartwork"); 
int index = nextSongname.indexOf(nextSongname.get(IplayerActivity.pos-2)); 
Uri newuri = Uri.parse(artworkkeyword.get(index+counter)); 

songname.setText(nextSongname.get(index+counter)); 
artistname.setText(nextArtistname.get(index+counter)); 
albumname.setText(nextAlbumname.get(index+counter)); 
path = nextPathname.get(index+counter); 
artworkimageview.setImageURI(newuri); 

try{ 
    playAudio(path); 
}catch(Exception e){ 
    e.getStackTrace(); 
} 

if(j < nextPathname.size()-1){ 
    counter+=1; 
}else{ 
    index = 0; 
    counter = 0; 
    j = 0; 
} 
j++; 
+3

你得到了什麼樣的例外?這裏你沒有足夠的信息。 – avgvstvs

+2

沒有堆棧跟蹤,可能會出錯的東西太多了。我的猜測是你在計數器和位置上玩的太多了(很多'-1','-2','index + counter',..發生在那個代碼中) – Molske

回答

0

我建議移動內部的休耕代碼力嘗試趕上:

songname.setText(nextSongname.get(index+counter)); 
artistname.setText(nextArtistname.get(index+counter)); 
albumname.setText(nextAlbumname.get(index+counter)); 
path = nextPathname.get(index+counter); 
artworkimageview.setImageURI(newuri); 

......你可能會得到:索引超出範圍的例外。

其他推薦是在播放音頻之前檢查空格或null的路徑。 (以C#示例)

if(!string.IsNullOrWhiteSpace(path)) 
    playAudio(path); 

注意:j未使用。