所以我们可以通过下面的语句获得: AudioManager audiomanage = (AudioManager)getAcitivity().getSystemService(Context.AUDIO_SERVICE...); audiomanager就是我们定义的控制系统声音的对象。...,AudioManager.ADJUST_LOWER, AudioManager.FX_FOCUS_NAVIGATION_UP); } //增加音量..., AudioManager.FX_FOCUS_NAVIGATION_UP); } 常用方法: android audioManager获取音量...: 先获取AudioManager实例, AudioManager mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE
requestedMode, pid, mode)); // 记录dumpsys audio 日志 int streamType = getActiveStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE
框架文档地址:GameAIs.Com LollipopCreator:AudioManager LollipopCreator游戏框架 游戏客户端开发中,由于制作人或者策划立项的不同,导致前端开发并不像后端框架不变...return -1 } 注意点:主资源位置Master/data/sound 子游戏资源位置SubModules/${moduleName}/data/sound 实例代码 class AudioManager...this.model.musicFile = null this.model.musicID = -1 } } } window.audioMgr = new AudioManager
应用还必须为这两个调用注册 AudioManager.OnAudioFocusChangeListener,以便接收回调并管理自己的音量。...API介绍 处理音频焦点都是通过AudioManager这个类,如下是获得该类实例的方法: AudioManager am = (AudioManager) mContext.getSystemService...abandonAudioFocus(OnAudioFocusChangeListener l) 参数通上 AudioManager.OnAudioFocusChangeListener ....; case AudioManager.AUDIOFOCUS_LOSS: // TBD 停止播放 break; case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT...AudioManager mAudioManager; private AudioFocusRequest mFocusRequest; private AudioManager.OnAudioFocusChangeListener
AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER; int flags = AudioManager.FX_FOCUS_NAVIGATION_UP...audioManager.setStreamVolume(AudioManager.STREAM_SYSTEM, audioManager.getStreamVolume...(AudioManager.STREAM_SYSTEM), AudioManager.FX_KEY_CLICK); } else { audioManager.setSpeakerphoneOn...), AudioManager.FX_KEY_CLICK); } else { audioManager.setMode(AudioManager.MODE_IN_CALL...(AudioManager.STREAM_VOICE_CALL), AudioManager.FX_KEY_CLICK); } } } audioManager.setMode(
audioManager; audioManager = ((AudioManager) getSystemService(AUDIO_SERVICE)); 3.设置几个属性 private...(AudioManager.ROUTE_SPEAKER); // 获取当前通话音量 currVolume = audioManager.getStreamVolume...audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, audioManager.getStreamMaxVolume...(AudioManager.STREAM_VOICE_CALL), AudioManager.STREAM_VOICE_CALL);...(false); audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, currVolume,
audioSource.PlayOneShot(jumpClip, 10f); } 声音管理类: 单例模式(Mono中与C#中的单例有区别) AudioSource audioSource; //单例保证AudioManager...的唯一性 private static AudioManager instance; public static AudioManager Instance {...instance == null) { //在找的时候构造出来一个Object GameObject go = new GameObject("audioManager..."); go.AddComponent(); } return instance;...} } //禁止外接通过new的方式获取该类 private AudioManager() { } private void Awake() {
, //音量类型 volume, AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI..., //音量类型 volume, AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI..., //音量类型 volume, AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI..., //音量类型 volume, AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI...AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL ); } } }
android的消息提示(震动和提示音),实现代码如下所示: public class VibratorUtil { protected AudioManager audioManager;...static final int MIN_TIME_OUT = 4000; //时间间隔 long lastNotificationTime; public VibratorUtil() { audioManager...= (AudioManager) MyApp.getContext().getSystemService(Context.AUDIO_SERVICE); //此方法是由Context调用的 vibrator...{ return; } try { lastNotificationTime = System.currentTimeMillis(); if (audioManager.getRingerMode...() == AudioManager.RINGER_MODE_SILENT) { return; } long[] pattern = new long[]{0,
, 0 则不显示 AudioManager.FLAG_ALLOW_RINGER_MODES 是否铃声模式 AudioManager.FLAG_VIBRATE 是否震动模式 AudioManager.FLAG_SHOW_VIBRATE_HINT...震动提示 AudioManager.FLAG_SHOW_SILENT_HINT 静音提示 AudioManager.FLAG_PLAY_SOUND 调整音量时播放声音 adjustStreamVolume..., AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI ) } 参数1:音量类型...参数2:音量调整方向 AudioManager.ADJUST_RAISE 音量逐渐递增 AudioManager.ADJUST_LOWER 音量逐渐递减 AudioManager.ADJUST_SAME..., AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI ) } Github
android.view.View") import("android.content.Context") import("android.media.MediaPlayer") import("android.media.AudioManager...com.androlua.Ticker") -- Ticker:定时触发器 activity.getSystemService(Context.AUDIO_SERVICE).setStreamVolume(AudioManager.STREAM_MUSIC..., 15, AudioManager.FLAG_SHOW_UI) --音量调大 activity.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION..., 15, AudioManager.FLAG_SHOW_UI) -- 和上面一模一样 activity.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION..., 15, AudioManager.FLAG_SHOW_UI) -- 设置音量为最大 end -- 相当于把返回键变成了音量最大键 return true end 总共34行,除去开头一大堆import
mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE..., AudioManager.FX_FOCUS_NAVIGATION_UP); currentVolume = mAudioManager .getStreamVolume...(AudioManager.STREAM_MUSIC); Log.i(TAG, "当前音量:" + currentVolume); } public void down(...AudioManager.ADJUST_LOWER, AudioManager.FX_FOCUS_NAVIGATION_UP); currentVolume = mAudioManager....getStreamVolume(AudioManager.STREAM_MUSIC); Log.i(TAG, "当前音量:" + currentVolume
例如我们要获取AudioManager,我们可以: AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); 获取的服务...可以看ContextImpl.java中的实现: static { ...... // 将AudioManager加入SYSTEM_SERVICE_MAP中,调用getSystemService...时, // 就会从SYSTEM_SERVICE_MAP得到AudioManager registerService(AUDIO_SERVICE, new ServiceFetcher()...}}); ...... } AudioManager是对IAudioService的封装,实际操作都是使用IAudioService进行的,看AudioManager中的代码: private...现在,我们就可以使用AudioManager中的isStreamMute(int streamType)方法了 ?
AudioManager对象才可以使用. eg : AudioManager audioManager = (AudioManager)getApplicationContext().getSystemService...(Context.AUDIO_SERVICE); 利用AudioManager获取当前音量的方法 : float currVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC...); 利用AudioManager获取当前系统最大音量方法 : float maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC...audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE); float currVolume = audioManager.getStreamVolume...(AudioManager.STREAM_MUSIC); float maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC
audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); private void setSpeakerphoneOn...(boolean on) { if(on) { audioManager.setSpeakerphoneOn(true); } else {...audioManager.setSpeakerphoneOn(false);//关闭扬声器 audioManager.setRouting(AudioManager.MODE_NORMAL..., AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL); setVolumeControlStream(AudioManager.STREAM_VOICE_CALL...); //把声音设定成Earpiece(听筒)出来,设定为正在通话中 audioManager.setMode(AudioManager.MODE_IN_CALL
(在 builder 中必须指明请求的音频焦点类型) AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE...: // 不允许播放 case AudioManager.AUDIOFOCUS_REQUEST_GRANTED: // 开始播放 } 音频焦点类型要点: AudioManager.AUDIOFOCUS_GAIN...调用 AudioManager 的 requestAudioFocus(…) 方法,需要用到实例化好的 AudioFocusRequest。...代码如下: AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); int..., AudioManager.AUDIOFOCUS_GAIN); switch (focusRequest) { case AudioManager.AUDIOFOCUS_REQUEST_FAILED
audioManager; private AudioManager.OnAudioFocusChangeListener listener; @Override protected void onResume...() { if (audioManager!...= null) { audioManager.abandonAudioFocus(listener); audioManager = null; } super.onResume...(); } @Override protected void onPause() { audioManager = (AudioManager) mContext.getSystemService...(listener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED
; private String mCurrentFilePath; private static AudioManager mInstance; private boolean isPrepared;...private AudioManager(String dir) { this.mDir = dir; } //单例模式:在这里实例化AudioManager并传入录音文件地址 public static...AudioManager getInstance(String dir) { if (mInstance == null) { synchronized (AudioManager.class) {...mAudioManager; private android.media.AudioManager audioManager; public AudioRecorderButton(Context context...() { audioManager.requestAudioFocus(onAudioFocusChangeListener, android.media.AudioManager.STREAM_MUSIC
领取专属 10元无门槛券
手把手带您无忧上云