1、方法一

public void onCreate(Bundle savedInstanceState) {     
super.onCreate(savedInstanceState); setContentView(R.layout.main); MediaPlayer mPlayer = MediaPlayer.create(FakeCallScreen.this, R.raw.mysoundfile); mPlayer.start(); }public void onDestroy() { mPlayer.stop(); super.onDestroy();}

2、方法二:

A SoundPool is a collection of samples that can be loaded into memory from a resource inside the APK or from a file in the file system. The SoundPool library uses the MediaPlayer service to decode the audio into a raw 16-bit PCM mono or stereo stream. This allows applications to ship with compressed streams without having to suffer the CPU load and latency of decompressing during playback.

/** * How many sounds can be played at once. */private static final int MAX_SOUND_POOL_STREAMS = 4;/** * Modify this as part of your own priority scheme. Higher numbers mean higher * priority. If you don't care, it's okay to use the same priority for every * sound. */private static final int NORMAL_PRIORITY = 10;private int mySoundId;@Overridepublic void setupContent() {    this.soundPool = new SoundPool(MAX_SOUND_POOL_STREAMS,            AudioManager.STREAM_MUSIC, 100);    this.mySoundId = this.soundPool.load(this.getApplicationContext(),            R.raw.mySound, 1);}@Overrideprivate void playMySound() {    this.soundPool.play(this.mySoundId, 1, 1, NORMAL_PRIORITY, 0, 1);}

更多相关文章

  1. android 查找联系人方法(支持首拼,全拼,英文)
  2. Android之TabHost的几种使用方法
  3. Android保持屏幕常亮的方法总结
  4. Android中RadioGroup RadioButton CheckBox多选按钮实现方法以及
  5. Android-Intent的使用方法详解
  6. Android将Uri转化为文件路径的方法
  7. android HTTP post方法时,如何使用cookies
  8. Android NDK之----- C调用Java [GetMethodID方法的使用]
  9. 一些常用SD卡操作的方法,APk管理之类的方法

随机推荐

  1. Android的设计模式
  2. Android配置打包名称
  3. 记住密码
  4. android酷炫翻页效果+图形分析
  5. Android方法的传递值及其改变
  6. android 处理图片工具
  7. Android之给图片添加水印效果
  8. Android(安卓)自定义显示图片Dialog
  9. Android新增keycode
  10. android 时间戳与日期格式的互相转换 以