There is such a method. He played melodies in a row by this example: https://stackoverflow.com/questions/7383387/setting-an-array-of-songs-using-mediaplayer It works like this: Melodies from the repro array. in order. You must match the melody and picture. That is, the soundsRawResId [idx] melody (r.raw.1) plays the animation at the element of the imageview arr_imageB 1 .startAnimation (anim);

public void playAllSongs() { idx = (idx + 1); if (idx >= 7) { idx = -1; playAllSongs(); } else { AssetFileDescriptor afd = getContext().getResources().openRawResourceFd(soundsRawResIds[idx]); arr_imageB[idx].startAnimation(anim); try { mediaPlayer.reset(); mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength()); mediaPlayer.prepare(); mediaPlayer.start(); afd.close(); } catch (IllegalArgumentException e) { Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e); } catch (IllegalStateException e) { Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e); } catch (IOException e) { Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e); } } } 

Arrays:

//music

 private int [] soundsRawResIds = new int[]{R.raw.1, R.raw.2, R.raw.3, R.raw.4, R.raw.5, R.raw.6, R.raw.7}; //изображения, инициализация for (int index = 0; index < buttonIds.length; index++) { arr_imageB[index] = (ImageView) rootViewB.findViewById(buttonIds[index]); } 
  • The problem is unclear and there are doubts that the code you presented still actually plays music from the array in a row - YuriySPb
  • @Yuriy SPb melodies in a row play, everything is normal. The problem in the header is indicated - upward
  • It is very strange that it works - for good, you need to play a new song in the listener when the playback ends, and not in a loop. And it is so unclear what prevents you from getting a picture from an array by index, if their lengths are the same - YuriySPb
  • I still don't understand what your problem is. I do not see any changes in the question either. You do not need a lot of cycles. One is enough. And even better without them at all. - Yuriy SPb
  • one
    You need to remove the loop and leave only one animation run from the array. The index used is the same as for the array of songs. - Yuriy SPb

3 answers 3

Everything works like a clock! What I need!

 public void playAllSongs() { idx = (idx + 1); if (idx >= 7) { idx = -1; playAllSongs(); } else { AssetFileDescriptor afd = getContext().getResources().openRawResourceFd(soundsRawResIds[idx]); if(idx-1<0){ //ничего не выполняется } else { arr_imageB[idx-1].clearAnimation(); } arr_imageB[idx].startAnimation(anim); try { mediaPlayer.reset(); mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength()); mediaPlayer.prepare(); mediaPlayer.start(); afd.close(); } catch (IllegalArgumentException e) { Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e); } catch (IllegalStateException e) { Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e); } catch (IOException e) { Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e); } } } 
  • @YuriiSPb and is it possible to add to this method pause and vosprizved. since pause? mediaPlayer.isPlaying ()) {mediaPlayer.pause (); } I haven’t rolled, stops, but does not reproduce - upward
  1. Run one song from the array with the index "counter".
  2. Run one anamization from the array with the index "counter".
  3. Increase counter by one.
  4. Hang up the listener to finish playing the song.
  5. In it repeat p1, p2 and p.3
  • Everything works, but I cannot understand how to remove such a bug, if I turn to a new melody, then the animation from the previous imagevie continues to work, but needs to be stopped. arr_imageB [idx] .clearAnimation (); I tried to stop it at the very beginning, but it didn't work out. Maybe hang setAnimationListener ?? - upward
  • arr_imageB[ index - 1 ].clearAnimation(); - as it should be. The main thing to the "-1" element of the array do not refer. - Yuriy SPb
  • @Yuriy SPb and call at the very beginning of the method? - upward
  • one
    Call a lot where and as much as possible. Just think a little where you are more comfortable. It is possible and in the beginning. But it must be correlated with the increment of your index. - Yuriy SPb
  • one
    Take this situation into consideration. If you know that the code will lead to an error - why write it? If you know that there will be an error at a certain moment - react to this ............... - YuriySPb

Create a Map of Map or List of Map for the loaded composition sheet. For an external container, use the file name (in the case of Map ) or the index (in the case of List ) as the key. For internal Map<String,Object> or Map<String,String> use as keys the strings "name","image","music" and as values ​​- the name of the composition, the path to the picture (or the picture itself, if Object ) and the path to the music file (or the track itself in the case of Object ).