如何创建更好的playSong方法?

时间:2013-12-21 17:29:36

标签: android eclipse playback

我想播放所选专辑中的一首歌。 问题是每当我点击一张专辑,选择歌曲时,playSong方法当然会播放第一首歌,因为代码第2部分(向下)。也许你看看我的代码,你可以帮助我。谢谢你很多,Vinzenz


第1部分:

.
. 
.
public void  playSong(int songIndex){
    // Play song
    try {
        mp.reset();
        mp.setDataSource(songsList.get(songIndex).get("songPath"));
        mp.prepare();
        mp.start();
        // Displaying Song title
        String songTitle = songsList.get(songIndex).get("songTitle");
        songTitleLabel.setText(songTitle);
.
. 
.

第2部分:

.
. 
.
public void onItemClick(AdapterView<?> a, View v, int position, long Title ) {
      if (cursor.moveToPosition(position)) {

        // getting listitem index
            int songIndex = position;
            // Starting new intent
            Intent in = new Intent();

            // Sending songIndex to BrowseActivity
            in.putExtra("songIndex", songIndex);

            setResult(100, in);
            // Closing PlayListView
            finish();


     }    
.
. 
.

0 个答案:

没有答案