Java tutorial
//package com.java2s; //License from project: Apache License import android.content.res.AssetFileDescriptor; import android.content.res.AssetManager; import android.media.MediaPlayer; public class Main { /** * Play video file from res folder. * Then call mediaPlayer.start(); * @param fileName * @param listener * @return * @throws Exception */ public static MediaPlayer playSound(AssetManager assetManager, String fileName, MediaPlayer.OnCompletionListener listener) throws Exception { MediaPlayer mediaPlayer = new MediaPlayer(); if (listener != null) { mediaPlayer.setOnCompletionListener(listener); } AssetFileDescriptor descriptor = assetManager.openFd(fileName); mediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength()); descriptor.close(); mediaPlayer.prepare(); return mediaPlayer; } }