I have two activities first one has public String var called songurl and button leads to the second activity and second activity has mediaplayer receive URL from the String var which is in the first activity and then start playing but the problem is the mediaplayer doesn't work and I got an error
here is MainActivity1.kt or .java as your language :-
lateinit var songurl :String
class MainActivity1 : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
songurl = "https//...... My URL"
var btnstart_MainActivity2:Button = findViewById(R.id.btn)
btnstart_MainActivity2.setOnClickListener {
startActivity(Intent(this,Main2Activity::class.java))
}
}
}
here is MainActivity2 :-
class Main2Activity : AppCompatActivity() {
lateinit var mediaplayer: MediaPlayer
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mediaplayer= MediaPlayer()
mediaplayer.setDataSource(songurl)
mediaplayer.prepare()
mediaplayer.start()
}
}
and here is the err
lateinit property songurl has not been initialized