Java Code Examples for android.media.AudioManager#playSoundEffect()
The following examples show how to use
android.media.AudioManager#playSoundEffect() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SoftKeyboard.java From AndroidKeyboard with GNU General Public License v3.0 | 6 votes |
/** * Play sound when key is pressed. */ private void playClick(int keyCode) { AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE); if (am != null) { switch (keyCode) { case 32: am.playSoundEffect(AudioManager.FX_KEYPRESS_SPACEBAR); break; case Keyboard.KEYCODE_DONE: case 10: am.playSoundEffect(AudioManager.FX_KEYPRESS_RETURN); break; case Keyboard.KEYCODE_DELETE: am.playSoundEffect(AudioManager.FX_KEYPRESS_DELETE); break; default: am.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD); } } }
Example 2
Source File: BleDevicesActivity.java From Bluetooth-Manager-for-Glass with MIT License | 6 votes |
@Override public void onLeScan(BluetoothDevice device, int rssi, byte[] bytes) { if (device.getName() != null) { BleDevice bleDevice = new BleDevice(device, rssi); if (!mDevices.contains(bleDevice)) { mDevices.add(bleDevice); AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audio.playSoundEffect(Sounds.SUCCESS); } else { int index = mDevices.indexOf(bleDevice); mDevices.get(index).setRssi(rssi); } runOnUiThread(new Runnable() { @Override public void run() { adapter = new BleDeviceCardScrollAdapter(BleDevicesActivity.this, mDevices); mCardScrollView.setAdapter(adapter); } }); } }
Example 3
Source File: UIManagerModule.java From react-native-GPay with MIT License | 5 votes |
@ReactMethod public void playTouchSound() { AudioManager audioManager = (AudioManager) getReactApplicationContext().getSystemService(Context.AUDIO_SERVICE); if (audioManager != null) { audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK); } }
Example 4
Source File: SliderActivity.java From gdk-apidemo-sample with Apache License 2.0 | 5 votes |
@Override public void onGracePeriodEnd() { // Play a SUCCESS sound to indicate the end of the grace period. AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); am.playSoundEffect(Sounds.SUCCESS); mGracePeriod = null; }
Example 5
Source File: SliderActivity.java From gdk-apidemo-sample with Apache License 2.0 | 5 votes |
@Override public void onGracePeriodCancel() { // Play a DIMISS sound to indicate the cancellation of the grace period. AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); am.playSoundEffect(Sounds.DISMISSED); mGracePeriod = null; }
Example 6
Source File: PairedDevicesListActivity.java From Bluetooth-Manager-for-Glass with MIT License | 5 votes |
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mSelectedDevice = (BluetoothDevice) mCardScrollView.getItemAtPosition(position); AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audio.playSoundEffect(Sounds.TAP); openOptionsMenu(); }
Example 7
Source File: PairDevicesActivity.java From Bluetooth-Manager-for-Glass with MIT License | 5 votes |
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audio.playSoundEffect(Sounds.TAP); mSelectedDevice = adapter.getItem(position); openOptionsMenu(); }
Example 8
Source File: BleDevicesActivity.java From Bluetooth-Manager-for-Glass with MIT License | 5 votes |
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audio.playSoundEffect(Sounds.TAP); mSelectedDevice = adapter.getItem(position); openOptionsMenu(); }
Example 9
Source File: PlumbleService.java From Plumble with GNU General Public License v3.0 | 5 votes |
@Override public void onUserTalkStateUpdated(IUser user) { if (isConnectionEstablished() && getSessionId() == user.getSession() && getTransmitMode() == Constants.TRANSMIT_PUSH_TO_TALK && user.getTalkState() == TalkState.TALKING && mPTTSoundEnabled) { AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); audioManager.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD, -1); } }
Example 10
Source File: KboardIME.java From kboard with GNU General Public License v3.0 | 4 votes |
private void playClick(){ AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE); am.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD, 0.3f); }
Example 11
Source File: KboardIME.java From kboard with GNU General Public License v3.0 | 4 votes |
private void playClick(){ AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE); am.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD, 0.3f); }
Example 12
Source File: BleServicesActivity.java From Bluetooth-Manager-for-Glass with MIT License | 4 votes |
private void onServiceClick(int position) { AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audio.playSoundEffect(Sounds.TAP); mSelectedService = adapter.getItem(position); openOptionsMenu(); }
Example 13
Source File: BleServicesActivity.java From Bluetooth-Manager-for-Glass with MIT License | 4 votes |
private void onCharacteristicClick(int position) { AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audio.playSoundEffect(Sounds.TAP); mSelectedCharacteristic = charAdapter.getItem(position); openOptionsMenu(); }
Example 14
Source File: AudioManagerUtils.java From DevUtils with Apache License 2.0 | 3 votes |
/** * 播放音效 * @param effectType {@link AudioManager#FX_KEY_CLICK}, * {@link AudioManager#FX_FOCUS_NAVIGATION_UP}, * {@link AudioManager#FX_FOCUS_NAVIGATION_DOWN}, * {@link AudioManager#FX_FOCUS_NAVIGATION_LEFT}, * {@link AudioManager#FX_FOCUS_NAVIGATION_RIGHT}, * {@link AudioManager#FX_KEYPRESS_STANDARD}, * {@link AudioManager#FX_KEYPRESS_SPACEBAR}, * {@link AudioManager#FX_KEYPRESS_DELETE}, * {@link AudioManager#FX_KEYPRESS_RETURN}, * {@link AudioManager#FX_KEYPRESS_INVALID}, * @param volume 音量大小 * @return {@code true} success, {@code false} fail */ public static boolean playSoundEffect(final int effectType, final float volume) { AudioManager audioManager = AppUtils.getAudioManager(); if (audioManager != null) { try { audioManager.playSoundEffect(effectType, volume); return true; } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "playSoundEffect"); } } return false; }