How to implement by pressing the Play button so that the songs from the array are played one after another: (now, if the song ends, the player stops)
private Button buttonPlayStop; private MediaPlayer mediaPlayer; private SeekBar seekBar; int index=0; public int[] soundsRawResIds = new int[]{R.raw.belarus, R.raw.russian, R.raw.japan, R.raw.litva, R.raw.england, R.raw.finlandia, R.raw.france}; private final Handler handler = new Handler(); @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.activity_main); initViews(); } private void initViews() { for(int i=0;i<soundsRawResIds.length;i++) { mediaPlayer = MediaPlayer.create(this, soundsRawResIds[i]); } buttonPlayStop = (Button) findViewById(R.id.ButtonPlayStop); mediaPlayer = MediaPlayer.create(this, soundsRawResIds[index]); seekBar = (SeekBar) findViewById(R.id.seekBar); seekBar.setMax(mediaPlayer.getDuration()); seekBar.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { seekChange(v); return false; } }); } private void seekChange(View v){ if(mediaPlayer.isPlaying()){ SeekBar sb = (SeekBar)v; mediaPlayer.seekTo(sb.getProgress()); } } public void playAndStop(View v){ if (buttonPlayStop.getText() == getString(R.string.play_str)) { buttonPlayStop.setText(getString(R.string.pause_str)); try{ mediaPlayer.start(); startPlayProgressUpdater(); }catch (IllegalStateException e) { mediaPlayer.pause(); } }else { buttonPlayStop.setText(getString(R.string.play_str)); mediaPlayer.pause(); } } public void startPlayProgressUpdater() { seekBar.setProgress(mediaPlayer.getCurrentPosition()); if (mediaPlayer.isPlaying()) { Runnable notification = new Runnable() { public void run() { startPlayProgressUpdater(); } }; handler.postDelayed(notification,1000); }else{ mediaPlayer.pause(); buttonPlayStop.setText(getString(R.string.play_str)); seekBar.setProgress(0); } } } Разметка: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <SeekBar android:layout_width="fill_parent" android:progress="0" android:max="100" android:layout_height="wrap_content" android:id="@+id/seekBar"/> <Button android:text="@string/play_str" android:textSize="15pt" android:textStyle="bold" android:onClick="playAndStop" android:id="@+id/ButtonPlayStop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginRight="-3dp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/timeSound" android:textSize="30sp" android:text="00:00" /> </LinearLayout>