The array must be defined as an array of integer elements since you access system resources, in this case for example R.raw.gallo
is an audio that must be found in the folder /raw
I see you use Kotlin, this is an example:
val audio = R.raw.gallo;
val mediaPlayer = MediaPlayer.create(this, audio).start()
I add more complete examples:
Play audio stored in /raw
to another activity to play through MediaPlayer
.
From your Activity
you realize the Intent
sending the value of your audio:
val intent = Intent(this, SecondActivity::class.java)
val message = R.raw.gallo;
intent.putExtra("audio", message)
startActivity(intent)
In the Activity
destination you receive the value and reproduce the audio:
val intent = getIntent();
val audio = intent.getIntExtra("audio",0)
val mediaPlayer = MediaPlayer.create(this, audio).start()
Play audios stored in /raw
to another activity to play through MediaPlayer
.
You make an array of integers containing the ids of the audios and the sendings in Intent
:
val intent = Intent(this, SecondActivity::class.java)
val message: IntArray = intArrayOf(R.raw.perro, R.raw.gato, R.raw.gallo, R.raw.crocodile);
intent.putExtra("audios", message)
startActivity(intent)
in the Activity
destination you receive the array of elements, and through the index you can indicate which element in the array to play:
val intent = getIntent();
val audios:IntArray = intent.getIntArrayExtra("audios")
val mediaPlayer = MediaPlayer.create(this, audios[2]).start()