VeronicaV
VeronicaV

Reputation: 19

Playing a video from removable SD card on Android device with VideoView using Kotlin

I'm working on an Android app (Lenovo tablet, API 33, Android 13.0) that displays a video depending on the selection made. I am able to play each video (.mp4) from the raw folder, but I'd like to store the videos removable micro SD card, since I'll have about 50 videos (~25MB each).

I am able to play a video stored in res/raw using the following code:

val packageName = "android.resource://" + getPackageName() + "/" + R.raw.crystal
val uri = Uri.parse(packageName)
videoView.setVideoURI(uri)
val mediaController = MediaController(this)
videoView.setMediaController(mediaController)
videoView.start()

Now I want to play the same video from a removable SD card:

Manifest

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Activity

val packageName = Environment.getExternalStorageDirectory().path + "/crystal.mp4"
val uri = Uri.parse(packageName)
videoView.setVideoURI(uri)
val mediaController = MediaController(this)
videoView.setMediaController(mediaController)
videoView.start()   

This doesn't work. I get a pop-up that says "Can't play this video".

All the examples I have found online seem pretty straightforward, so I'm not sure why this isn't working. Is my path wrong? What am I missing?

Upvotes: 0

Views: 100

Answers (0)

Related Questions