📅  最后修改于: 2022-03-11 15:00:30.234000             🧑  作者: Mango
class MainActivity2 : AppCompatActivity() {
var videoView: VideoView? = null
var mediaController: MediaController? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main2)
(findViewById(R.id.videoView) as VideoView?).also { videoView = it }
if (mediaController== null) {
val context = null
mediaController= context?.let { mediaController(it this) }
mediaController!!.setAnchorView(this.videoView)
}
videoView!!.setMediaController(mediaController)
val uriString = "android.resource://+packageName+ "/" +R.raw.bts"
videoView!!.setVideoURI(Uri.parse(uriString))
videoView!!.requestFocus()
videoView!!.start()
videoView!!.setOnCompletionListener { it MediaPlayer!
}
}