注意 videoview播放视频及时放在了 res/raw目录下,仍然需要读写权限
class MyVideoView(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) :
VideoView(context, attrs, defStyleAttr, defStyleRes) {
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : this(context, attrs, defStyleAttr, 0)
constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0,0)
constructor(context: Context?) : this(context, null, 0, 0)
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
val widthSize = View.getDefaultSize(0,widthMeasureSpec)
val heightSize = View.getDefaultSize(0,heightMeasureSpec)
setMeasuredDimension(widthMeasureSpec, heightMeasureSpec)
}
}
videoView.setVideoURI(Uri.parse("android.resource://$packageName/${R.raw.mainvideo}"))
videoView.setOnPreparedListener {
it.isLooping = true
it.setVolume(0.5f,0.5f)
it.start()
}
|