I encounteres the problem on Android Studio using Kotlin, the code should play a video file in the res/raw
folder but it stops at: val videoView = findViewById(R.id.testView)
Returning the error: Not enough information to infer type variable T
import android.net.Uri
import android.net.Uri.*
import android.os.Bundle
import android.widget.MediaController
import android.widget.VideoView
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//Find the VideoView class by its id
val videoView = findViewById(R.id.testView)
// Not enough information to infer type variable T
}
}
The video file is in MP4 format, i had to import the *.mp4 file type in the Android Studio settings.
The .xml file looks correct to me, and in the right folder: res/layout/activity_main.xml
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.video_player.MainActivity">
<VideoView
android:id="@+id/testView"
android:layout_width="wrap_content"
android:layout_height="308dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Add type to your variable:
val videoView: VideoView = findViewById(R.id.testView)
// or
val videoView = findViewById<VideoView>(R.id.testView)