Android通过摇晃手机的频率来控制声音的频率(5)
来源:未知 责任编辑:责任编辑 发表时间:2013-11-15 19:49 点击:次
20 mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
21 mSoundPoolMap = new HashMap<Integer, Integer>();
22 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
23 }
24
25
26 public void addSound(int index, String audioName) {
27 // mSoundPoolMap.put(1, mSoundPool.load(mContext, SoundID, 1));
28 try {
29 mSoundPoolMap.put(index, mSoundPool.load(mContext.getAssets().openFd(audioName), 1));
30 } catch (IOException e) {
31 e.printStackTrace();
32 }
33 }
34
35 // loopMode=0:play once; loopMode=-1:loop mode;
36 public void play(int index, int loopMode, float rate) {
37 if (mSoundEnable) {
38 this.loopMode = loopMode;
39 mRate = checkRate(rate);
40
41 int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
42 // float streamVolume = 0.1f;
43 // notes: for loop mode, the priority should be set to 0, else it can't be stopped
44 // mStreamID=mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, loopMode, mRate);
45 if (mPlayIndex < 0) {
46 mStreamID = mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 0, loopMode, mRate);
47 } else {
48 mStreamID = mSoundPool.play(mSoundPoolMap.get(mPlayIndex), streamVolume, streamVolume, 0, loopMode, mRate);
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>