- 首先在res下创建raw,然后将mp3音乐拷贝到raw下
- 直接贴代码吧
//开始播放声音 public class PlayVoice { private static MediaPlayer mediaPlayer; public static void playVoice(Context context){ try { mediaPlayer= MediaPlayer.create(context, R.raw.opening); mediaPlayer.start(); mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mediaPlayer.start(); } }); } catch (Exception e) { e.printStackTrace(); } } //停止播放声音 public static void stopVoice(){ if(null!=mediaPlayer) { mediaPlayer.stop(); } } }