public class FileUtils { private static MediaPlayer mediaPlayer; public static void stopMediaPlayer(){ if (mediaPlayer!=null) { mediaPlayer.stop(); mediaPlayer.pause(); mediaPlayer.release(); mediaPlayer = null; } } /** * 打开assets下的音乐mp3文件 */ public static void playAssetVoice(Context context,String tipMediaName) { try { stopMediaPlayer(); //播放 assets/a2.mp3 音乐文件 AssetFileDescriptor fd = context.getAssets().openFd(tipMediaName); if (mediaPlayer==null) mediaPlayer = new MediaPlayer(); mediaPlayer.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength()); mediaPlayer.prepare(); mediaPlayer.start(); } catch (IOException e) { e.printStackTrace(); } } }