列出视图音乐列表,歌曲

时间:2014-04-17 19:44:06

标签: java android media-player

我在原始文件夹中添加了开发播放音乐的应用程序。 通过点击歌曲播放音乐到ListView。但完成后音乐不会传递给下一首歌。我该怎么办?

我正在使用翻译抱歉

public class LoadedActivity extends Activity {
MediaPlayer mp;
View View;
ListView listView;
Drawable Drawble;
ImageButton OynatButonu;         
ImageButton DurdurButonu;
ImageButton IleriButonu;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.loaded_layout);

    Field[] fields = R.raw.class.getFields();
    String[] mediaList = new String[fields.length];
    for (int count = 0; count < fields.length; count++)
        mediaList[count] = fields[count].getName();

    listView = (ListView) findViewById(R.id.music_list);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(
            LoadedActivity.this, android.R.layout.simple_list_item_1,
            mediaList);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View v, int position,
                long id) {
            if (View != null)
                ((TextView) View).setBackgroundDrawable(Drawble);
            Drawble = ((TextView) v).getBackground();

            String uri = "android.resource://" + getPackageName() + "/raw/"
                    + ((TextView) v).getText();

            if (mp != null && mp.isPlaying())
                mp.stop();

            mp = MediaPlayer.create(getApplicationContext(), Uri.parse(uri));
            mp.start();

            ((TextView) v).setBackgroundColor(Color.WHITE);
            ((TextView) v).setTextColor(Color.RED);
            View = v;                         
        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu, menu);
    return true;
    }
}

2 个答案:

答案 0 :(得分:0)

尝试将OnCompletionListener添加到您的媒体播放器中,如下所示:

mp.setOnCompletionListener(new OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {
            mp.setDataSource("your_next_song_url");
            mp.prepare();
            mp.start();

        }
    });

答案 1 :(得分:-1)

给出了这个错误。 mp.setdatasource(&#34; /原料/&#34);这是真的吗?

enter image description here