How Do I Play Files in the Assets Directory in MediaPlayer?

Asked 2 years ago, Updated 2 years ago, 37 views

I'd like to play a video file in the assets directory in the MediaPlayer class on Android. What should I do?

android

2022-09-30 10:50

1 Answers

setDataSource with FileDescriptor to play.

mMediaPlayer=newMediaPlayer();
AssetFileDescriptor fd=getAsset().openFd("video.mp4");
mMediaPlayer.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
mMediaPlayer.setDisplay(holder);
mMediaPlayer.prepare();
mMediaPlayer.start();


2022-09-30 10:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.