//我正在尝试从SDCARD播放音乐,一个接一个,但我想在编辑第一首音乐后播放第二首音乐。它应该自动发生。我是新手android,任何帮助将不胜感激。与给代码。我可以播放音乐
class Play : AppCompatActivity() {
var play: ImageView? = null
var stop: ImageView? = null
var AudioSavePathInDevice = "Blesson"
var mediaPlayer: MediaPlayer? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_play)
play = findViewById(R.id.play) as ImageView
stop = findViewById(R.id.stop) as ImageView
play!!.setOnClickListener {
play!!.visibility = View.INVISIBLE
stop!!.visibility = View.VISIBLE
val file = intent.extras["file"]
for (hello in 1..3) {
AudioSavePathInDevice = File("$file/bless$hello.mp3").toString()
Toast.makeText(this, AudioSavePathInDevice, Toast.LENGTH_LONG).show()
mediaPlayer = MediaPlayer()
try {
mediaPlayer!!.setDataSource(AudioSavePathInDevice)
mediaPlayer!!.prepare()
} catch (e: IOException) {
Toast.makeText(this, "Recoring not found",
Toast.LENGTH_LONG).show()
}
mediaPlayer!!.start()
Toast.makeText(this, "Recording Playing",
Toast.LENGTH_LONG).show()
mediaPlayer!!.setOnCompletionListener{}
try {
mediaPlayer!!.stop()
mediaPlayer!!.release()
}catch (ex: Exception){ }
}
}
}
}