List of usage examples for android.media SoundPool SoundPool
public SoundPool(int maxStreams, int streamType, int srcQuality)
From source file:dk.bearware.gui.MainActivity.java
@Override protected void onResume() { super.onResume(); if (audioIcons != null) audioIcons.release();//from w w w. j av a2 s .c om sounds.clear(); audioIcons = new SoundPool(1, AudioManager.STREAM_MUSIC, 0); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); audioManager.setMode(prefs.getBoolean(Preferences.PREF_SOUNDSYSTEM_VOICEPROCESSING, false) ? AudioManager.MODE_IN_COMMUNICATION : AudioManager.MODE_NORMAL); audioManager.setSpeakerphoneOn(prefs.getBoolean(Preferences.PREF_SOUNDSYSTEM_SPEAKERPHONE, false)); if (prefs.getBoolean("server_lost_audio_icon", true)) { sounds.put(SOUND_SERVERLOST, audioIcons.load(getApplicationContext(), R.raw.serverlost, 1)); } if (prefs.getBoolean("rx_tx_audio_icon", true)) { sounds.put(SOUND_VOICETXON, audioIcons.load(getApplicationContext(), R.raw.on, 1)); sounds.put(SOUND_VOICETXOFF, audioIcons.load(getApplicationContext(), R.raw.off, 1)); } if (prefs.getBoolean("personal_message_audio_icon", true)) { sounds.put(SOUND_USERMSG, audioIcons.load(getApplicationContext(), R.raw.user_message, 1)); } if (prefs.getBoolean("channel_message_audio_icon", true)) { sounds.put(SOUND_CHANMSG, audioIcons.load(getApplicationContext(), R.raw.channel_message, 1)); } if (prefs.getBoolean("broadcast_message_audio_icon", true)) { sounds.put(SOUND_BCASTMSG, audioIcons.load(getApplicationContext(), R.raw.channel_message, 1)); } if (prefs.getBoolean("files_updated_audio_icon", true)) { sounds.put(SOUND_FILESUPDATE, audioIcons.load(getApplicationContext(), R.raw.fileupdate, 1)); } if (prefs.getBoolean("voiceact_triggered_icon", true)) { sounds.put(SOUND_VOXON, audioIcons.load(getApplicationContext(), R.raw.voiceact_on, 1)); sounds.put(SOUND_VOXOFF, audioIcons.load(getApplicationContext(), R.raw.voiceact_off, 1)); } if (prefs.getBoolean("transmitready_icon", true)) { sounds.put(SOUND_TXREADY, audioIcons.load(getApplicationContext(), R.raw.txqueue_start, 1)); sounds.put(SOUND_TXSTOP, audioIcons.load(getApplicationContext(), R.raw.txqueue_stop, 1)); } if (prefs.getBoolean("userjoin_icon", true)) { sounds.put(SOUND_USERJOIN, audioIcons.load(getApplicationContext(), R.raw.user_join, 1)); } if (prefs.getBoolean("userleft_icon", true)) { sounds.put(SOUND_USERLEFT, audioIcons.load(getApplicationContext(), R.raw.user_left, 1)); } getTextMessagesAdapter().showLogMessages(prefs.getBoolean("show_log_messages", true)); getWindow().getDecorView().setKeepScreenOn(prefs.getBoolean("keep_screen_on_checkbox", false)); createStatusTimer(); }
From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @Override//from www .j a v a 2 s.co m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(LOG_TAG, "onCreate() : " + savedInstanceState); setContentView(R.layout.activity_jet_pack_elf); // App Invites mInvitesFragment = AppInvitesFragment.getInstance(this); // App Measurement mMeasurement = FirebaseAnalytics.getInstance(this); MeasurementManager.recordScreenView(mMeasurement, getString(R.string.analytics_screen_rocket)); // [ANALYTICS SCREEN]: Rocket Sleigh AnalyticsManager.initializeAnalyticsTracker(this); AnalyticsManager.sendScreenView(R.string.analytics_screen_rocket); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { ImmersiveModeHelper.setImmersiveSticky(getWindow()); ImmersiveModeHelper.installSystemUiVisibilityChangeListener(getWindow()); } mIntroVideo = (VideoView) findViewById(R.id.intro_view); mIntroControl = findViewById(R.id.intro_control_view); if (savedInstanceState == null) { String path = "android.resource://" + getPackageName() + "/" + R.raw.jp_background; mBackgroundPlayer = new MediaPlayer(); try { mBackgroundPlayer.setDataSource(this, Uri.parse(path)); mBackgroundPlayer.setLooping(true); mBackgroundPlayer.prepare(); mBackgroundPlayer.start(); } catch (IOException e) { e.printStackTrace(); } boolean nomovie = false; if (getIntent().getBooleanExtra("nomovie", false)) { nomovie = true; } else if (Build.MANUFACTURER.toUpperCase().contains("SAMSUNG")) { // nomovie = true; } if (!nomovie) { mIntroControl.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { endIntro(); } }); path = "android.resource://" + getPackageName() + "/" + R.raw.intro_wipe; mIntroVideo.setVideoURI(Uri.parse(path)); mIntroVideo.setOnCompletionListener(this); mIntroVideo.start(); mMoviePlaying = true; } else { mIntroControl.setOnClickListener(null); mIntroControl.setVisibility(View.GONE); mIntroVideo.setVisibility(View.GONE); } } else { mIntroControl.setOnClickListener(null); mIntroControl.setVisibility(View.GONE); mIntroVideo.setVisibility(View.GONE); } mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // For hit indication. mHandler = new Handler(); // Get the main UI handler for posting update events DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); Log.d(LOG_TAG, "Width: " + dm.widthPixels + " Height: " + dm.heightPixels + " Density: " + dm.density); mScreenHeight = dm.heightPixels; mScreenWidth = dm.widthPixels; mSlotWidth = mScreenWidth / SLOTS_PER_SCREEN; // Setup the random number generator mRandom = new Random(); mRandom.setSeed(System.currentTimeMillis()); // This is ok. We are not looking for cryptographically secure random here! mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); // Setup the background/foreground mBackgroundLayout = (LinearLayout) findViewById(R.id.background_layout); mBackgroundScroll = (HorizontalScrollView) findViewById(R.id.background_scroll); mForegroundLayout = (LinearLayout) findViewById(R.id.foreground_layout); mForegroundScroll = (HorizontalScrollView) findViewById(R.id.foreground_scroll); mBackgrounds = new Bitmap[6]; mBackgrounds2 = new Bitmap[6]; mExitTransitions = new Bitmap[6]; mEntryTransitions = new Bitmap[6]; // Need to vertically scale background to fit the screen. Checkthe image size // compared to screen size and scale appropriately. We will also use the matrix to translate // as we move through the level. Bitmap bmp = BitmapFactory.decodeResource(getResources(), BACKGROUNDS[0]); Log.d(LOG_TAG, "Bitmap Width: " + bmp.getWidth() + " Height: " + bmp.getHeight() + " Screen Width: " + dm.widthPixels + " Height: " + dm.heightPixels); mScaleY = (float) dm.heightPixels / (float) bmp.getHeight(); mScaleX = (float) (dm.widthPixels * 2) / (float) bmp.getWidth(); // Ensure that a single bitmap is 2 screens worth of time. (Stock xxhdpi image is 3840x1080) if ((mScaleX != 1.0f) || (mScaleY != 1.0f)) { Bitmap tmp = Bitmap.createScaledBitmap(bmp, mScreenWidth * 2, mScreenHeight, false); if (tmp != bmp) { bmp.recycle(); bmp = tmp; } } BackgroundLoadTask.createTwoBitmaps(bmp, mBackgrounds, mBackgrounds2, 0); // Load the initial background view addNextImages(0); addNextImages(0); mWoodObstacles = new TreeMap<Integer, Bitmap>(); mWoodObstacleList = new ArrayList<Integer>(); mWoodObstacleIndex = 0; // We need the bitmaps, so we do pre-load here synchronously. initObstaclesAndPreLoad(WOOD_OBSTACLES, 3, mWoodObstacles, mWoodObstacleList); mCaveObstacles = new TreeMap<Integer, Bitmap>(); mCaveObstacleList = new ArrayList<Integer>(); mCaveObstacleIndex = 0; initObstacles(CAVE_OBSTACLES, 2, mCaveObstacleList); mFactoryObstacles = new TreeMap<Integer, Bitmap>(); mFactoryObstacleList = new ArrayList<Integer>(); mFactoryObstacleIndex = 0; initObstacles(FACTORY_OBSTACLES, 2, mFactoryObstacleList); // Setup the elf mElf = (ImageView) findViewById(R.id.elf_image); mThrust = (ImageView) findViewById(R.id.thrust_image); mElfLayout = (LinearLayout) findViewById(R.id.elf_container); loadElfImages(); updateElf(false); // Elf should be the same height relative to the height of the screen on any platform. Matrix scaleMatrix = new Matrix(); mElfScale = ((float) dm.heightPixels * 0.123f) / (float) mElfBitmap.getHeight(); // On a 1920x1080 xxhdpi screen, this makes the elf 133 pixels which is the height of the drawable. scaleMatrix.preScale(mElfScale, mElfScale); mElf.setImageMatrix(scaleMatrix); mThrust.setImageMatrix(scaleMatrix); mElfPosX = (dm.widthPixels * 15) / 100; // 15% Into the screen mElfPosY = (dm.heightPixels - ((float) mElfBitmap.getHeight() * mElfScale)) / 2; // About 1/2 way down. mElfVelX = (float) dm.widthPixels / 3000.0f; // We start at 3 seconds for a full screen to scroll. mGravityAccelY = (float) (2 * dm.heightPixels) / (float) Math.pow((1.2 * 1000.0), 2.0); // a = 2*d/t^2 Where d = height in pixels and t = 1.2 seconds mThrustAccelY = (float) (2 * dm.heightPixels) / (float) Math.pow((0.7 * 1000.0), 2.0); // a = 2*d/t^2 Where d = height in pixels and t = 0.7 seconds // Setup the control view mControlView = findViewById(R.id.control_view); mGestureDetector = new GestureDetector(this, this); mGestureDetector.setIsLongpressEnabled(true); mGestureDetector.setOnDoubleTapListener(this); mScoreLabel = getString(R.string.score); mScoreText = (TextView) findViewById(R.id.score_text); mScoreText.setText("0"); mPlayPauseButton = (ImageView) findViewById(R.id.play_pause_button); mExit = (ImageView) findViewById(R.id.exit); // Is Tv? mIsTv = TvUtil.isTv(this); if (mIsTv) { mScoreText.setText(mScoreLabel + ": 0"); mPlayPauseButton.setVisibility(View.GONE); mExit.setVisibility(View.GONE); // move scoreLayout position to the Top-Right corner. View scoreLayout = findViewById(R.id.score_layout); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) scoreLayout.getLayoutParams(); params.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM); params.addRule(RelativeLayout.ALIGN_PARENT_TOP); params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT); params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); final int marginTop = getResources().getDimensionPixelOffset(R.dimen.overscan_margin_top); final int marginLeft = getResources().getDimensionPixelOffset(R.dimen.overscan_margin_left); params.setMargins(marginLeft, marginTop, 0, 0); scoreLayout.setLayoutParams(params); scoreLayout.setBackground(null); scoreLayout.findViewById(R.id.score_text_seperator).setVisibility(View.GONE); } else { mPlayPauseButton.setEnabled(false); mPlayPauseButton.setOnClickListener(this); mExit.setOnClickListener(this); } mBigPlayButtonLayout = findViewById(R.id.big_play_button_layout); mBigPlayButtonLayout.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // No interaction with the screen below this one. return true; } }); mBigPlayButton = (ImageButton) findViewById(R.id.big_play_button); mBigPlayButton.setOnClickListener(this); // For showing points when getting presents. mPlus100 = (ImageView) findViewById(R.id.plus_100); m100Anim = new AlphaAnimation(1.0f, 0.0f); m100Anim.setDuration(1000); m100Anim.setFillBefore(true); m100Anim.setFillAfter(true); mPlus500 = (ImageView) findViewById(R.id.plus_500); m500Anim = new AlphaAnimation(1.0f, 0.0f); m500Anim.setDuration(1000); m500Anim.setFillBefore(true); m500Anim.setFillAfter(true); // Get the obstacle layouts ready. No obstacles on the first screen of a level. // Prime with a screen full of obstacles. mObstacleLayout = (LinearLayout) findViewById(R.id.obstacles_layout); mObstacleScroll = (HorizontalScrollView) findViewById(R.id.obstacles_scroll); // Initialize the present bitmaps. These are used repeatedly so we keep them loaded. mGiftBoxes = new Bitmap[GIFT_BOXES.length]; for (int i = 0; i < GIFT_BOXES.length; i++) { mGiftBoxes[i] = BitmapFactory.decodeResource(getResources(), GIFT_BOXES[i]); } // Add starting obstacles. First screen has presents. Next 3 get obstacles. addFirstScreenPresents(); // addFinalPresentRun(); // This adds 2 screens of presents // addNextObstacles(0, 1); addNextObstacles(0, 3); // Setup the sound pool mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0); mSoundPool.setOnLoadCompleteListener(this); mCrashSound1 = mSoundPool.load(this, R.raw.jp_crash_1, 1); mCrashSound2 = mSoundPool.load(this, R.raw.jp_crash_2, 1); mCrashSound3 = mSoundPool.load(this, R.raw.jp_crash_3, 1); mGameOverSound = mSoundPool.load(this, R.raw.jp_game_over, 1); mJetThrustSound = mSoundPool.load(this, R.raw.jp_jet_thrust, 1); mLevelUpSound = mSoundPool.load(this, R.raw.jp_level_up, 1); mScoreBigSound = mSoundPool.load(this, R.raw.jp_score_big, 1); mScoreSmallSound = mSoundPool.load(this, R.raw.jp_score_small, 1); mJetThrustStream = 0; if (!mMoviePlaying) { doCountdown(); } }
From source file:com.ieeton.agency.activity.ChatActivity.java
private int initSoundPool() { mSoundPool = new SoundPool(5, AudioManager.STREAM_ALARM, 0); int loadId = mSoundPool.load(ChatActivity.this, R.raw.notificationsound, 1); return loadId; }
From source file:com.b44t.messenger.NotificationsController.java
private void playInChatSound() { if (!inChatSoundEnabled || MediaController.getInstance().isRecordingAudio()) { return;//from w ww . ja va2 s.c om } try { if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) { return; } } catch (Exception e) { FileLog.e("messenger", e); } try { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Context.MODE_PRIVATE); int notifyOverride = getNotifyOverride(preferences, opened_dialog_id); if (notifyOverride == 2) { return; } notificationsQueue.postRunnable(new Runnable() { @Override public void run() { if (Math.abs(System.currentTimeMillis() - lastSoundPlay) <= 500) { return; } lastSoundPlay = System.currentTimeMillis(); try { if (soundPool == null) { soundPool = new SoundPool(3, AudioManager.STREAM_SYSTEM, 0); soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { if (status == 0) { soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f); } } }); } if (soundIn == 0 && !soundInLoaded) { soundInLoaded = true; soundIn = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_in, 1); } if (soundIn != 0) { soundPool.play(soundIn, 1.0f, 1.0f, 1, 0, 1.0f); } } catch (Exception e) { FileLog.e("messenger", e); } } }); } catch (Exception e) { FileLog.e("messenger", e); } }
From source file:org.vshgap.android.NotificationsController.java
private void playInChatSound() { if (!inChatSoundEnabled) { return;//from ww w .jav a2 s . co m } try { if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) { return; } } catch (Exception e) { FileLog.e("tmessages", e); } try { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Context.MODE_PRIVATE); int notifyOverride = getNotifyOverride(preferences, openned_dialog_id); if (notifyOverride == 2) { return; } notificationsQueue.postRunnable(new Runnable() { @Override public void run() { if (lastSoundPlay > System.currentTimeMillis() - 500) { return; } try { if (soundPool == null) { soundPool = new SoundPool(4, AudioManager.STREAM_SYSTEM, 0); } if (soundIn == 0) { soundIn = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_in, 1); } soundPool.play(soundIn, 1.0f, 1.0f, 1, 0, 1.0f); /*if (mediaPlayerIn == null) { AssetFileDescriptor assetFileDescriptor = ApplicationLoader.applicationContext.getResources().openRawResourceFd(R.raw.sound_in); if (assetFileDescriptor != null) { mediaPlayerIn = new MediaPlayer(); mediaPlayerIn.setAudioStreamType(AudioManager.STREAM_SYSTEM); mediaPlayerIn.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength()); mediaPlayerIn.setLooping(false); assetFileDescriptor.close(); mediaPlayerIn.prepare(); } } try { mediaPlayerIn.pause(); mediaPlayerIn.seekTo(0); } catch (Exception e) { FileLog.e("tmessages", e); } mediaPlayerIn.start();*/ } catch (Exception e) { FileLog.e("tmessages", e); } } }); } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:org.vshgap.android.NotificationsController.java
public void playOutChatSound() { if (!inChatSoundEnabled) { return;/*from w w w .jav a 2s. c o m*/ } try { if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) { return; } } catch (Exception e) { FileLog.e("tmessages", e); } notificationsQueue.postRunnable(new Runnable() { @Override public void run() { try { if (soundPool == null) { soundPool = new SoundPool(4, AudioManager.STREAM_SYSTEM, 0); } if (soundOut == 0) { soundOut = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_out, 1); } soundPool.play(soundOut, 1.0f, 1.0f, 1, 0, 1.0f); /*if (mediaPlayerOut == null) { AssetFileDescriptor assetFileDescriptor = ApplicationLoader.applicationContext.getResources().openRawResourceFd(R.raw.sound_out); if (assetFileDescriptor != null) { mediaPlayerOut = new MediaPlayer(); mediaPlayerOut.setAudioStreamType(AudioManager.STREAM_SYSTEM); mediaPlayerOut.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength()); mediaPlayerOut.setLooping(false); assetFileDescriptor.close(); mediaPlayerOut.prepare(); } } try { mediaPlayerOut.pause(); mediaPlayerOut.seekTo(0); } catch (Exception e) { FileLog.e("tmessages", e); } mediaPlayerOut.start();*/ } catch (Exception e) { FileLog.e("tmessages", e); } } }); }
From source file:org.telegram.messenger.NotificationsController.java
private void playInChatSound() { if (!inChatSoundEnabled) { return;// w w w. ja v a 2 s . com } try { if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) { return; } } catch (Exception e) { FileLog.e("tmessages", e); } try { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Context.MODE_PRIVATE); int notifyOverride = getNotifyOverride(preferences, openned_dialog_id); if (notifyOverride == 2) { return; } notificationsQueue.postRunnable(new Runnable() { @Override public void run() { if (lastSoundPlay > System.currentTimeMillis() - 500) { return; } try { if (soundPool == null) { soundPool = new SoundPool(2, AudioManager.STREAM_SYSTEM, 0); soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { if (status == 0) { soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f); } } }); } if (soundIn == 0 && !soundInLoaded) { soundInLoaded = true; soundIn = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_in, 1); } if (soundIn != 0) { soundPool.play(soundIn, 1.0f, 1.0f, 1, 0, 1.0f); } } catch (Exception e) { FileLog.e("tmessages", e); } } }); } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:com.goftagram.telegram.messenger.NotificationsController.java
private void playInChatSound() { if (!inChatSoundEnabled) { return;/*from w w w. j a v a 2 s. c o m*/ } try { if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) { return; } } catch (Exception e) { FileLog.e("tmessages", e); } try { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Context.MODE_PRIVATE); int notifyOverride = getNotifyOverride(preferences, openned_dialog_id); if (notifyOverride == 2) { return; } notificationsQueue.postRunnable(new Runnable() { @Override public void run() { if (Math.abs(System.currentTimeMillis() - lastSoundPlay) <= 500) { return; } try { if (soundPool == null) { soundPool = new SoundPool(2, AudioManager.STREAM_SYSTEM, 0); soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { if (status == 0) { soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f); } } }); } if (soundIn == 0 && !soundInLoaded) { soundInLoaded = true; soundIn = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_in, 1); } if (soundIn != 0) { soundPool.play(soundIn, 1.0f, 1.0f, 1, 0, 1.0f); } } catch (Exception e) { FileLog.e("tmessages", e); } } }); } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:com.panahit.telegramma.NotificationsController.java
private void playInChatSound() { if (!inChatSoundEnabled || MediaController.getInstance().isRecordingAudio()) { return;//w ww . ja v a2 s . c om } try { if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) { return; } } catch (Exception e) { FileLog.e("tmessages", e); } try { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Context.MODE_PRIVATE); int notifyOverride = getNotifyOverride(preferences, openned_dialog_id); if (notifyOverride == 2) { return; } notificationsQueue.postRunnable(new Runnable() { @Override public void run() { if (Math.abs(System.currentTimeMillis() - lastSoundPlay) <= 500) { return; } try { if (soundPool == null) { soundPool = new SoundPool(3, AudioManager.STREAM_SYSTEM, 0); soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { if (status == 0) { soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f); } } }); } if (soundIn == 0 && !soundInLoaded) { soundInLoaded = true; soundIn = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_in, 1); } if (soundIn != 0) { soundPool.play(soundIn, 1.0f, 1.0f, 1, 0, 1.0f); } } catch (Exception e) { FileLog.e("tmessages", e); } } }); } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:com.b44t.messenger.NotificationsController.java
public void playOutChatSound() { if (!inChatSoundEnabled || MediaController.getInstance().isRecordingAudio()) { return;/*from w ww .j a va 2 s . c om*/ } try { if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) { return; } } catch (Exception e) { FileLog.e("messenger", e); } notificationsQueue.postRunnable(new Runnable() { @Override public void run() { try { if (Math.abs(System.currentTimeMillis() - lastSoundOutPlay) <= 100) { return; } lastSoundOutPlay = System.currentTimeMillis(); if (soundPool == null) { soundPool = new SoundPool(3, AudioManager.STREAM_SYSTEM, 0); soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { if (status == 0) { soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f); } } }); } if (soundOut == 0 && !soundOutLoaded) { soundOutLoaded = true; soundOut = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_out, 1); } if (soundOut != 0) { soundPool.play(soundOut, 1.0f, 1.0f, 1, 0, 1.0f); } } catch (Exception e) { FileLog.e("messenger", e); } } }); }