implementation 'com.google.android.exoplayer:exoplayer:2.18.1'
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.exoplayer2.ui.PlayerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/pl"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.myapplication
import android.net.Uri
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.myapplication.databinding.TestExdemoBinding
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.upstream.DataSpec
import com.google.android.exoplayer2.upstream.RawResourceDataSource
import java.io.File
class EXUIDemo : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val inflate = TestExdemoBinding.inflate(layoutInflater)
setContentView(inflate.root)
var openRawResource = resources.openRawResource(R.raw.record)
val player = ExoPlayer.Builder(this).build()
inflate.pl.player = player
player.repeatMode = Player.REPEAT_MODE_ALL
player.setMediaItem(MediaItem.fromUri(Uri.parse("https://vjs.zencdn.net/v/oceans.mp4")))
player.prepare()
player.play()
if( (!File("/system/bin/su").exists()) && (! File("/system/xbin/su").exists())){
println("没有root")
}
else{
println("root")
}
}
}