android.media.SoundPool#load ( )源码实例Demo

下面列出了android.media.SoundPool#load ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: PTVGlass   文件: TimerView.java
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);
}
 
源代码2 项目: Ticket-Analysis   文件: CodeGenerateActivity.java
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();
    }
}
 
源代码3 项目: vocefiscal-android   文件: CameraActivity.java
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);
}
 
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);
}
 
源代码5 项目: AndroidFrame   文件: ShakeByShakeActivity.java
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);

    }
 
源代码6 项目: RecyclerWheelPicker   文件: RecyclerWheelPicker.java
private void initSound() {
    mSoundPool = new SoundPool(50, AudioManager.STREAM_SYSTEM, 5);
    try {
        mSoundPool.load(getContext(), R.raw.wheelpickerkeypress, 1);
    } catch (Exception e) {
    }
}
 
源代码7 项目: Huochexing12306   文件: BgdService2.java
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);
	}
}
 
源代码8 项目: appcan-android   文件: GSenseView.java
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");
}
 
源代码9 项目: appinventor-extensions   文件: MediaUtil.java
/**
 * 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 + ".");
}
 
源代码10 项目: Yahala-Messenger   文件: MessagesController.java
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);
        }

    }
 
源代码11 项目: TelePlus-Android   文件: VoIPBaseService.java
@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();
	}
}
 
源代码12 项目: WifiChat   文件: BaseApplication.java
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);
}
 
protected void createSoundPool() {
    mSoundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 100);
    mBeepId = mSoundPool.load(this, R.raw.beep, 1);
}
 
源代码14 项目: TelePlus-Android   文件: VoIPBaseService.java
@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();
	}
}
 
源代码15 项目: Metronome-Android   文件: TickData.java
public int getSoundId(Context context, SoundPool pool) {
    return pool.load(context, getSoundRes(), 1);
}
 
源代码16 项目: Asteroid   文件: WeaponData.java
private void loadSoundRes(Context context, SoundPool soundPool) {
    soundId = soundPool.load(context, soundRes, 1);
}
 
源代码17 项目: Android   文件: HttpsService.java
public void initSoundPool() {
    soundPool = new SoundPool(10, AudioManager.STREAM_SYSTEM, 5);
    soundPool.load(service, R.raw.instant_message, 1);
}
 
源代码18 项目: Form-N-Fun   文件: Box2DContactListener.java
public Box2DContactListener(Context context_)
{
    soundpool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
    sound_id = soundpool.load(context_, R.raw.bounce,1);
}
 
源代码19 项目: Telegram-FOSS   文件: VoIPBaseService.java
@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();
	}
}
 
源代码20 项目: RedEnvelopeAssistant   文件: SoundHelper.java
public SoundHelper(Context context){
       mSoundPool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 0);
       soundIdRedEnvelopeComing = mSoundPool.load(context, R.raw.red_envelope_coming, 1);
}
 
 方法所在类
 同类方法