Android - Read Multimedia File from Assets folder

To read a multimedia file from assets folder via MediaPlayer, you could use the following code

AssetManager am = getAssets();
//Imagine you have a folder assets/mp4
AssetFileDescriptor afd = am.openFd("mp4/test.mp4")
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
//I am assuming that you have knowledge in getting a surfaceHolder from SurfaceView
mediaPlayer.setDisplay(surfaceHolder);
mediaPlayer.prepare();
mediaPlayer.start();

Comments

Popular Posts