Java Code Examples for android.media.SoundPool#load()

The following examples show how to use android.media.SoundPool#load() . 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: TimerView.java    From PTVGlass with MIT License 6 votes vote down vote up
public TimerView(Context context, AttributeSet attrs, int style) {
    super(context, attrs, style);

    mSoundPool = new SoundPool(MAX_STREAMS, AudioManager.STREAM_MUSIC, 0);
    mTimerFinishedSoundId = mSoundPool.load(context, R.raw.timer_finished, SOUND_PRIORITY);

    LayoutInflater.from(context).inflate(R.layout.card_timer, this);

    mHoursView = (TextView) findViewById(R.id.hours);
    mMinutesView = (TextView) findViewById(R.id.minutes);
    mSecondsView = (TextView) findViewById(R.id.seconds);
    mTipView = (TextView) findViewById(R.id.tip);
    mTipView.setText(context.getResources().getString(R.string.timer_finished));
    mTipView.setVisibility(View.INVISIBLE);

    mWhiteColor = context.getResources().getColor(R.color.white);
    mRedColor = context.getResources().getColor(R.color.red);

    mTimer = new Timer();
    mTimer.setListener(mTimerListener);
    mTimer.setDurationMillis(0);
}
 
Example 2
Source File: CameraActivity.java    From vocefiscal-android with Apache License 2.0 6 votes vote down vote up
private void setupSound() 
{		
	spool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
	spool.setOnLoadCompleteListener(new OnLoadCompleteListener() 
	{

		@Override
		public void onLoadComplete(SoundPool soundPool, int sampleId, int status) 
		{
			if(status==0)
			{
				if(sampleId==soundID)
					canPlaySound = true;
			}				
		}
	});


	soundID = spool.load(getApplicationContext(), R.raw.one_click, 1);
}
 
Example 3
Source File: CodeGenerateActivity.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
private void shake() {
    SoundPool soundPool = new SoundPool(1, AudioManager.STREAM_SYSTEM, 5);
    int weiChatAudio = soundPool.load(CodeGenerateActivity.this, R.raw.weichat_audio, 1);
    Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
    //发出提示音
    soundPool.play(weiChatAudio, 1, 1, 0, 0, 1);
    vibrator.vibrate(300);
    generateGroup();
    isShaking = true;
    try {
        Thread.sleep(100);
        isShaking = false;
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
 
Example 4
Source File: GameView.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 5 votes vote down vote up
public void loadSounds(String directory) {
	// Sounds
	sounds = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
	biteSound = sounds.load(directory + "/apple.wav", 1);
	crashSound = sounds.load(directory + "/crash.wav", 1);
	appearSound = sounds.load(directory + "/appear.wav", 1);
}
 
Example 5
Source File: MessagesController.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
public MessagesController() {

        MessagesStorage storage = MessagesStorage.getInstance();
        SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
        preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
        fontSize = preferences.getInt("fons_size", 16);

        try {
            soundPool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 0);
            sound = soundPool.load(ApplicationLoader.applicationContext, R.raw.electronic, 1);
        } catch (Exception e) {
            FileLog.e("yahala", e);
        }

    }
 
Example 6
Source File: ShakeByShakeActivity.java    From AndroidFrame with Apache License 2.0 5 votes vote down vote up
protected void initView() {
//初始化SoundPool
        mSoundPool = new SoundPool(1, AudioManager.STREAM_SYSTEM, 5);
        mWeiChatAudio = mSoundPool.load(this, R.raw.shake_sound, 1);

//获取Vibrator震动服务
        mVibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);

    }
 
Example 7
Source File: MediaUtil.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Loads the audio specified by mediaPath into the given SoundPool and
 * returns the sound id.
 *
 * Note that if the mediaPath is a content URI or an URL, the audio must be
 * copied to a temp file and then loaded from there. This could have
 * performance implications.
 *
 * @param soundPool the SoundPool
 * @param form the Form
 * @param mediaPath the path to the media
 */
public static int loadSoundPool(SoundPool soundPool, Form form, String mediaPath)
    throws IOException {
  MediaSource mediaSource = determineMediaSource(form, mediaPath);
  switch (mediaSource) {
    case ASSET:
      return soundPool.load(getAssetsIgnoreCaseAfd(form,mediaPath), 1);

    case REPL_ASSET:
      form.assertPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
      return soundPool.load(replAssetPath(mediaPath), 1);

    case SDCARD:
      form.assertPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
      return soundPool.load(mediaPath, 1);

    case FILE_URL:
      if (isExternalFileUrl(mediaPath)) {
        form.assertPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
      }
      return soundPool.load(fileUrlToFilePath(mediaPath), 1);

    case CONTENT_URI:
    case URL:
      File tempFile = cacheMediaTempFile(form, mediaPath, mediaSource);
      return soundPool.load(tempFile.getAbsolutePath(), 1);

    case CONTACT_URI:
      throw new IOException("Unable to load audio for contact " + mediaPath + ".");
  }

  throw new IOException("Unable to load audio " + mediaPath + ".");
}
 
Example 8
Source File: GSenseView.java    From appcan-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void init() {
    finder = ResoureFinder.getInstance(getContext());
    soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
    soundId = soundPool.load(getContext(), finder.getRawId("collision"), 1);
    touchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
    DisplayMetrics dm = getResources().getDisplayMetrics();
    bitmapBall = BitmapFactory.decodeResource(getResources(), finder.getDrawableId("platform_myspace_ball"));
    bitmapHole = BitmapFactory.decodeResource(getResources(), finder.getDrawableId("platform_myspace_hole"));
    bitmapW = bitmapBall.getWidth();
    bitmapH = bitmapBall.getHeight();
    radius = bitmapW / 2;
    dissAreaLeft = 200 * dm.density;
    dissAreaTop = 50 * dm.density;
    dissAreaRight = dissAreaLeft + bitmapHole.getWidth();
    dissAreaBottom = dissAreaTop + bitmapHole.getHeight();
    activity = (Activity) getContext();
    Rect rectgle = new Rect();
    Window window = activity.getWindow();
    window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
    windowWidth = rectgle.width();
    windowHeight = rectgle.height();
    mVibrator = (Vibrator) activity.getApplication().getSystemService(Service.VIBRATOR_SERVICE);
    sm = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE);
    setBackgroundDrawable(finder.getDrawable("platform_myspace_gsense_bg_shape"));
    params = new WindowManager.LayoutParams();
    params.height = windowHeight;
    params.width = windowWidth;
    params.type = WindowManager.LayoutParams.TYPE_APPLICATION | WindowManager.LayoutParams.FIRST_SUB_WINDOW;
    params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_BLUR_BEHIND;// 模态,不能获得焦点,背景失焦
    params.alpha = 1.0f;
    params.format = PixelFormat.TRANSPARENT;
    params.gravity = Gravity.LEFT | Gravity.TOP;
    params.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
    params.x = dm.widthPixels - windowWidth;
    params.y = dm.heightPixels - windowHeight;
    params.windowAnimations = finder.getStyleId("Anim_platform_myspace_fade");
}
 
Example 9
Source File: RecyclerWheelPicker.java    From RecyclerWheelPicker with Apache License 2.0 5 votes vote down vote up
private void initSound() {
    mSoundPool = new SoundPool(50, AudioManager.STREAM_SYSTEM, 5);
    try {
        mSoundPool.load(getContext(), R.raw.wheelpickerkeypress, 1);
    } catch (Exception e) {
    }
}
 
Example 10
Source File: BgdService2.java    From Huochexing12306 with Apache License 2.0 5 votes vote down vote up
private void doAlarm() {
	if (mCurrMInfo.isVibrate()){
		mVibrator.vibrate(1000);
	}
	if (mCurrMInfo.isRing()){
		SoundPool soundPool = new SoundPool(2, AudioManager.STREAM_SYSTEM, 5);
		soundPool.load(this, R.raw.ticket_alarm, 1);
		soundPool.play(1, 1, 1, 0, 0, 1);
	}
}
 
Example 11
Source File: SoundHelper.java    From RedEnvelopeAssistant with MIT License 4 votes vote down vote up
public SoundHelper(Context context){
       mSoundPool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 0);
       soundIdRedEnvelopeComing = mSoundPool.load(context, R.raw.red_envelope_coming, 1);
}
 
Example 12
Source File: VoIPBaseService.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onCreate() {
	super.onCreate();
	if (BuildVars.LOGS_ENABLED) {
		FileLog.d("=============== VoIPService STARTING ===============");
	}
	try {
		AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER)!=null) {
			int outFramesPerBuffer = Integer.parseInt(am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER));
			TgVoip.setBufferSize(outFramesPerBuffer);
		} else {
			TgVoip.setBufferSize(AudioTrack.getMinBufferSize(48000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT) / 2);
		}

		cpuWakelock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "telegram-voip");
		cpuWakelock.acquire();

		btAdapter=am.isBluetoothScoAvailableOffCall() ? BluetoothAdapter.getDefaultAdapter() : null;

		IntentFilter filter = new IntentFilter();
		filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
		if(!USE_CONNECTION_SERVICE){
			filter.addAction(ACTION_HEADSET_PLUG);
			if(btAdapter!=null){
				filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
				filter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
			}
			filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
		}
		registerReceiver(receiver, filter);

		soundPool = new SoundPool(1, AudioManager.STREAM_VOICE_CALL, 0);
		spConnectingId = soundPool.load(this, R.raw.voip_connecting, 1);
		spRingbackID = soundPool.load(this, R.raw.voip_ringback, 1);
		spFailedID = soundPool.load(this, R.raw.voip_failed, 1);
		spEndId = soundPool.load(this, R.raw.voip_end, 1);
		spBusyId = soundPool.load(this, R.raw.voip_busy, 1);

		am.registerMediaButtonEventReceiver(new ComponentName(this, VoIPMediaButtonReceiver.class));

		if(!USE_CONNECTION_SERVICE && btAdapter!=null && btAdapter.isEnabled()){
			int headsetState=btAdapter.getProfileConnectionState(BluetoothProfile.HEADSET);
			updateBluetoothHeadsetState(headsetState==BluetoothProfile.STATE_CONNECTED);
			//if(headsetState==BluetoothProfile.STATE_CONNECTED)
			//	am.setBluetoothScoOn(true);
			for (StateListener l : stateListeners)
				l.onAudioSettingsChanged();
		}
	} catch (Exception x) {
		if (BuildVars.LOGS_ENABLED) {
			FileLog.e("error initializing voip controller", x);
		}
		callFailed();
	}
}
 
Example 13
Source File: Box2DContactListener.java    From Form-N-Fun with MIT License 4 votes vote down vote up
public Box2DContactListener(Context context_)
{
    soundpool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
    sound_id = soundpool.load(context_, R.raw.bounce,1);
}
 
Example 14
Source File: HttpsService.java    From Android with MIT License 4 votes vote down vote up
public void initSoundPool() {
    soundPool = new SoundPool(10, AudioManager.STREAM_SYSTEM, 5);
    soundPool.load(service, R.raw.instant_message, 1);
}
 
Example 15
Source File: WeaponData.java    From Asteroid with Apache License 2.0 4 votes vote down vote up
private void loadSoundRes(Context context, SoundPool soundPool) {
    soundId = soundPool.load(context, soundRes, 1);
}
 
Example 16
Source File: TickData.java    From Metronome-Android with Apache License 2.0 4 votes vote down vote up
public int getSoundId(Context context, SoundPool pool) {
    return pool.load(context, getSoundRes(), 1);
}
 
Example 17
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onCreate() {
	super.onCreate();
	if (BuildVars.LOGS_ENABLED) {
		FileLog.d("=============== VoIPService STARTING ===============");
	}
	AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER)!=null) {
		int outFramesPerBuffer = Integer.parseInt(am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER));
		VoIPController.setNativeBufferSize(outFramesPerBuffer);
	} else {
		VoIPController.setNativeBufferSize(AudioTrack.getMinBufferSize(48000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT) / 2);
	}
	try {
		cpuWakelock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "telegram-voip");
		cpuWakelock.acquire();

		btAdapter=am.isBluetoothScoAvailableOffCall() ? BluetoothAdapter.getDefaultAdapter() : null;

		IntentFilter filter = new IntentFilter();
		filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
		if(!USE_CONNECTION_SERVICE){
			filter.addAction(ACTION_HEADSET_PLUG);
			if(btAdapter!=null){
				filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
				filter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
			}
			filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
		}
		registerReceiver(receiver, filter);

		soundPool = new SoundPool(1, AudioManager.STREAM_VOICE_CALL, 0);
		spConnectingId = soundPool.load(this, R.raw.voip_connecting, 1);
		spRingbackID = soundPool.load(this, R.raw.voip_ringback, 1);
		spFailedID = soundPool.load(this, R.raw.voip_failed, 1);
		spEndId = soundPool.load(this, R.raw.voip_end, 1);
		spBusyId = soundPool.load(this, R.raw.voip_busy, 1);

		am.registerMediaButtonEventReceiver(new ComponentName(this, VoIPMediaButtonReceiver.class));

		if(!USE_CONNECTION_SERVICE && btAdapter!=null && btAdapter.isEnabled()){
			int headsetState=btAdapter.getProfileConnectionState(BluetoothProfile.HEADSET);
			updateBluetoothHeadsetState(headsetState==BluetoothProfile.STATE_CONNECTED);
			//if(headsetState==BluetoothProfile.STATE_CONNECTED)
			//	am.setBluetoothScoOn(true);
			for (StateListener l : stateListeners)
				l.onAudioSettingsChanged();
		}

	} catch (Exception x) {
		if (BuildVars.LOGS_ENABLED) {
			FileLog.e("error initializing voip controller", x);
		}
		callFailed();
	}
}
 
Example 18
Source File: ModifyAttributesActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void createSoundPool() {
    mSoundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 100);
    mBeepId = mSoundPool.load(this, R.raw.beep, 1);
}
 
Example 19
Source File: BaseApplication.java    From WifiChat with GNU General Public License v2.0 4 votes vote down vote up
private void initNotification() {
    notiMediaplayer = new SoundPool(3, AudioManager.STREAM_SYSTEM, 5);
    notiSoundPoolID = notiMediaplayer.load(this, R.raw.crystalring, 1);
    notiVibrator = (Vibrator) getSystemService(Service.VIBRATOR_SERVICE);
}
 
Example 20
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onCreate() {
	super.onCreate();
	if (BuildVars.LOGS_ENABLED) {
		FileLog.d("=============== VoIPService STARTING ===============");
	}
	AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER)!=null) {
		int outFramesPerBuffer = Integer.parseInt(am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER));
		VoIPController.setNativeBufferSize(outFramesPerBuffer);
	} else {
		VoIPController.setNativeBufferSize(AudioTrack.getMinBufferSize(48000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT) / 2);
	}
	try {
		cpuWakelock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "telegram-voip");
		cpuWakelock.acquire();

		btAdapter=am.isBluetoothScoAvailableOffCall() ? BluetoothAdapter.getDefaultAdapter() : null;

		IntentFilter filter = new IntentFilter();
		filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
		if(!USE_CONNECTION_SERVICE){
			filter.addAction(ACTION_HEADSET_PLUG);
			if(btAdapter!=null){
				filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
				filter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
			}
			filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
		}
		registerReceiver(receiver, filter);

		soundPool = new SoundPool(1, AudioManager.STREAM_VOICE_CALL, 0);
		spConnectingId = soundPool.load(this, R.raw.voip_connecting, 1);
		spRingbackID = soundPool.load(this, R.raw.voip_ringback, 1);
		spFailedID = soundPool.load(this, R.raw.voip_failed, 1);
		spEndId = soundPool.load(this, R.raw.voip_end, 1);
		spBusyId = soundPool.load(this, R.raw.voip_busy, 1);

		am.registerMediaButtonEventReceiver(new ComponentName(this, VoIPMediaButtonReceiver.class));

		if(!USE_CONNECTION_SERVICE && btAdapter!=null && btAdapter.isEnabled()){
			int headsetState=btAdapter.getProfileConnectionState(BluetoothProfile.HEADSET);
			updateBluetoothHeadsetState(headsetState==BluetoothProfile.STATE_CONNECTED);
			//if(headsetState==BluetoothProfile.STATE_CONNECTED)
			//	am.setBluetoothScoOn(true);
			for (StateListener l : stateListeners)
				l.onAudioSettingsChanged();
		}

	} catch (Exception x) {
		if (BuildVars.LOGS_ENABLED) {
			FileLog.e("error initializing voip controller", x);
		}
		callFailed();
	}
}