Android Open Source - NotATop Sound Control






From Project

Back to project page NotATop.

License

The source code is released under:

GNU General Public License

If you think the Android project NotATop listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.gg.module;
/*w w  w.j  a va2 s.c o  m*/
import java.util.HashMap;
import java.util.Map;
import com.gg.view.R;
import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;

public class SoundControl {
  
  private MediaPlayer music ;  //music ????
  public AudioManager am;  //?????????????????
  private SoundPool soundPool ; // short music

  private boolean soundOn ; //short music control
  
  private Context context ;  
  
  private Map<Integer , Integer> soundMap;   //??????Id????????????Id?????????
  
  
  public SoundControl(Context context){
    init(context);
  }
  
  //??????????????
  private void initMusic(){
    music = MediaPlayer.create(context, R.raw.backmusic);
    music.setLooping(true);
  }
  
  
  //??????????????
  private void initSound(){
    soundPool = new SoundPool(10,AudioManager.STREAM_MUSIC,100);
    
    soundMap = new HashMap<Integer,Integer>();
    
    soundMap.put(R.raw.choose, soundPool.load(context, R.raw.choose,1));
    
    soundMap.put(R.raw.end, soundPool.load(context, R.raw.end,1));
    
    soundMap.put(R.raw.pai, soundPool.load(context, R.raw.pai,1));
    
    soundMap.put(R.raw.runing, soundPool.load(context, R.raw.runing,1));
    
  }      

  //????????????????
  public void init(Context c){
  
    context = c ;
  
    initMusic();
    
    initSound();
  }
  
  
  //????????????
  public boolean isSoundOn(){
    return soundOn;
  }
  
  
  //???????????
  public void playSound(int resId){
    am=(AudioManager)context.getSystemService(context.AUDIO_SERVICE);
      float audioMaxVolumn=am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);  //??????AudioManager?????????????
      float audioCurrentVolumn=am.getStreamVolume(AudioManager.STREAM_MUSIC);//??????AudioManager??????????
      float volumnRatio=audioCurrentVolumn/audioMaxVolumn;
      if(isSoundOn() == false)//????????????
      return ;
      soundPool.play(
          soundMap.get(resId),           //?????????id
          volumnRatio,             //??????????
          volumnRatio,             //??????????
          1,                   //???????0????
          0,               //?????????0????????-1????????
          1                  //?????? ???????0.5-2.0???1????????
    );
    
    Integer soundId = soundMap.get(resId);
    if(soundId != null)
      soundPool.play(soundId, 1, 1, 1, 0, 1);
  }
  
  
  //???????
  public void setMusic(){
    if(music.isPlaying()){
      music.pause();
      soundOn = false;
    }
    else{
      music.start();
      soundOn = true;
    }
  }
  
  
  //????????
  public void paisound(){
    playSound(R.raw.pai);
  }
  
  public void end(){
    playSound(R.raw.end);
  }
  
  public void choose(){
    playSound(R.raw.choose);
  }
  
  public void running(){
    playSound(R.raw.runing);
  }
  
  
  //??????????????
  public void releasemusic(){
    music.release();
    soundPool.release();
  }
  
}




Java Source Code List

com.gg.game.ClassicGame.java
com.gg.game.ClassicGame.java
com.gg.game.GameFrame.java
com.gg.game.GameFrame.java
com.gg.game.TimeGame.java
com.gg.game.TimeGame.java
com.gg.module.DrawBackground.java
com.gg.module.DrawBackground.java
com.gg.module.DrawScore.java
com.gg.module.DrawScore.java
com.gg.module.DrawTrack.java
com.gg.module.DrawTrack.java
com.gg.module.SelectControl.java
com.gg.module.SelectControl.java
com.gg.module.SoundControl.java
com.gg.module.SoundControl.java
com.gg.module.VoiceControl.java
com.gg.module.VoiceControl.java
com.gg.top.BasicTop.java
com.gg.top.BasicTop.java
com.gg.top.DrawCircle.java
com.gg.top.DrawCircle.java
com.gg.top.DrawCone.java
com.gg.top.DrawCone.java
com.gg.top.DrawCylinder.java
com.gg.top.DrawCylinder.java
com.gg.top.DrawTop.java
com.gg.top.DrawTop.java
com.gg.util.Circle.java
com.gg.util.Circle.java
com.gg.util.Constant.java
com.gg.util.Constant.java
com.gg.util.DateUtil.java
com.gg.util.DateUtil.java
com.gg.util.Direction.java
com.gg.util.Direction.java
com.gg.util.Line.java
com.gg.util.Line.java
com.gg.util.Point.java
com.gg.util.Point.java
com.gg.util.TextureRect.java
com.gg.util.TextureRect.java
com.gg.util.TrackPoint.java
com.gg.util.TrackPoint.java
com.gg.util.Track.java
com.gg.util.Track.java
com.gg.util.Utils.java
com.gg.util.Utils.java
com.gg.view.ClassicGameSurfaceView.java
com.gg.view.ClassicGameSurfaceView.java
com.gg.view.EndSurfaceView.java
com.gg.view.EndSurfaceView.java
com.gg.view.FirstTimeSurfaceView.java
com.gg.view.FirstTimeSurfaceView.java
com.gg.view.GameModeSurfaceView.java
com.gg.view.GameModeSurfaceView.java
com.gg.view.HelpSurfaceView.java
com.gg.view.HelpSurfaceView.java
com.gg.view.MainActivity.java
com.gg.view.MainActivity.java
com.gg.view.MainMenuSurfaceView.java
com.gg.view.MainMenuSurfaceView.java
com.gg.view.ScoreSurfaceView.java
com.gg.view.ScoreSurfaceView.java
com.gg.view.SelectSurfaceView.java
com.gg.view.SelectSurfaceView.java
com.gg.view.SurfaceViewFactory.java
com.gg.view.SurfaceViewFactory.java
com.gg.view.TimeGameSurfaceView.java
com.gg.view.TimeGameSurfaceView.java
com.gg.view.WelcomeSurfaceView.java
com.gg.view.WelcomeSurfaceView.java