SoundPool soundPool;
 public void initsound(){
  soundPool=new SoundPool(4,AudioManager.STREAM_MUSIC,1);
  soundPool.load(this,R.raw.th,1);
  
  }
  
  public void play(int loop){
  AudioManager mgr=(AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
  float streamVolume=mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
  float streamVolumeMax=mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
  float volume=streamVolume/streamVolumeMax;
  soundPool.play(R.raw.th, volume, volume, 1, loop, 1f);
  }这两个方法有问题吗??

解决方案 »

  1.   

    有问题!play的soundID参数错了SoundPool soundPool;
    int  soundID; public void initsound(){
              soundPool=new SoundPool(4,AudioManager.STREAM_MUSIC,1);
              soundID=soundPool.load(this,R.raw.th,1);
              
          }
          
          public void play(int loop){
              AudioManager mgr=(AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
              float streamVolume=mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
              float streamVolumeMax=mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
              float volume=streamVolume/streamVolumeMax;
              soundPool.play(soundID, volume, volume, 1, loop, 1f);
          }
      

  2.   

    可以去看看这篇文章。里面将得清楚
    http://blog.csdn.net/ch_984326013/article/details/6615707
      

  3.   

    ls的看看lz用soundPool.play((R.raw.th, volume, volume, 1, loop, 1f);不是资源ID要用load返回的soundID