我正在尝试从SD卡播放音乐

//我试图从SDCARD一个接一个播放音乐,但是我想在编辑第一首音乐之后播放第二首音乐。 它应该自动发生。 我是新来的机器人,任何帮助将不胜感激。 与给的代码。 我可以播放音乐

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){ } } } } } 

Interesting Posts