Search in sources :

Example 6 with SoundPool

use of android.media.SoundPool in project android-gltron by Chluverman.

the class SoundManager method initSounds.

public static void initSounds(Context theContext) {
    mContext = theContext;
    mSoundPool = new SoundPool(MAX_SOUNDS, AudioManager.STREAM_MUSIC, 0);
    mSoundPoolMap = new HashMap<Integer, Integer>();
    mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
}
Also used : SoundPool(android.media.SoundPool)

Example 7 with SoundPool

use of android.media.SoundPool in project SeeSik by GHHM.

the class LoadingActivity method onCreate.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {
        SoundPool loadingSound = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
        int soundbeep = loadingSound.load(this.getApplication(), R.raw.loading2, 1);
        Thread.sleep(600);
        loadingSound.play(soundbeep, 1f, 1f, 0, 0, 1f);
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    startActivity(new Intent(this, MainActivity.class));
    finish();
}
Also used : Intent(android.content.Intent) SoundPool(android.media.SoundPool)

Example 8 with SoundPool

use of android.media.SoundPool in project android_frameworks_base by crdroidandroid.

the class KeyguardViewMediator method setupLocked.

private void setupLocked() {
    mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    mWM = WindowManagerGlobal.getWindowManagerService();
    mTrustManager = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE);
    mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
    mShowKeyguardWakeLock.setReferenceCounted(false);
    mProfileManager = ProfileManager.getInstance(mContext);
    IntentFilter filter = new IntentFilter();
    filter.addAction(DELAYED_KEYGUARD_ACTION);
    filter.addAction(DELAYED_LOCK_PROFILE_ACTION);
    filter.addAction(Intent.ACTION_SHUTDOWN);
    mContext.registerReceiver(mBroadcastReceiver, filter);
    mKeyguardDisplayManager = new KeyguardDisplayManager(mContext);
    mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
    mLockPatternUtils = new LockPatternUtils(mContext);
    KeyguardUpdateMonitor.setCurrentUser(ActivityManager.getCurrentUser());
    // Assume keyguard is showing (unless it's disabled) until we know for sure...
    setShowingLocked(!shouldWaitForProvisioning() && !mLockPatternUtils.isLockScreenDisabled(KeyguardUpdateMonitor.getCurrentUser()));
    updateInputRestrictedLocked();
    mTrustManager.reportKeyguardShowingChanged();
    mStatusBarKeyguardViewManager = SystemUIFactory.getInstance().createStatusBarKeyguardViewManager(mContext, mViewMediatorCallback, mLockPatternUtils);
    final ContentResolver cr = mContext.getContentResolver();
    mDeviceInteractive = mPM.isInteractive();
    mLockSounds = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
    String soundPath = Settings.Global.getString(cr, Settings.Global.LOCK_SOUND);
    if (soundPath != null) {
        mLockSoundId = mLockSounds.load(soundPath, 1);
    }
    if (soundPath == null || mLockSoundId == 0) {
        Log.w(TAG, "failed to load lock sound from " + soundPath);
    }
    soundPath = Settings.Global.getString(cr, Settings.Global.UNLOCK_SOUND);
    if (soundPath != null) {
        mUnlockSoundId = mLockSounds.load(soundPath, 1);
    }
    if (soundPath == null || mUnlockSoundId == 0) {
        Log.w(TAG, "failed to load unlock sound from " + soundPath);
    }
    soundPath = Settings.Global.getString(cr, Settings.Global.TRUSTED_SOUND);
    if (soundPath != null) {
        mTrustedSoundId = mLockSounds.load(soundPath, 1);
    }
    if (soundPath == null || mTrustedSoundId == 0) {
        Log.w(TAG, "failed to load trusted sound from " + soundPath);
    }
    int lockSoundDefaultAttenuation = mContext.getResources().getInteger(com.android.internal.R.integer.config_lockSoundVolumeDb);
    mLockSoundVolume = (float) Math.pow(10, (float) lockSoundDefaultAttenuation / 20);
    mHideAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.lock_screen_behind_enter);
}
Also used : IntentFilter(android.content.IntentFilter) KeyguardDisplayManager(com.android.keyguard.KeyguardDisplayManager) LockPatternUtils(com.android.internal.widget.LockPatternUtils) SoundPool(android.media.SoundPool) ContentResolver(android.content.ContentResolver)

Example 9 with SoundPool

use of android.media.SoundPool in project AndroidSDK-RecipeBook by gabu.

the class Recipe061 method onResume.

// ホームボタンで閉じて戻ってきた時に
// MediaPlayerを正しい状態にしてあげるため
// onCreateではなくonResumeで準備する
@Override
public void onResume() {
    super.onResume();
    mMediaPlayer = MediaPlayer.create(this, R.raw.sample);
    mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {

        public void onPrepared(MediaPlayer mp) {
            isPrepared = true;
        // 準備ができて自動的に再生したいなら、ここでstartメソッドを呼ぶ
        // mp.start();
        }
    });
    mSoundPool = new SoundPool(MAX_SOUND_COUNT, AudioManager.STREAM_MUSIC, 0);
    mSounds[0] = mSoundPool.load(this, R.raw.sample, 1);
}
Also used : OnPreparedListener(android.media.MediaPlayer.OnPreparedListener) SoundPool(android.media.SoundPool) MediaPlayer(android.media.MediaPlayer)

Example 10 with SoundPool

use of android.media.SoundPool in project coursera-android by aporter.

the class AudioVideoAudioManagerActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    // Get reference to the AudioManager
    mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
    // Display current volume level in TextView
    final TextView tv = (TextView) findViewById(R.id.textView1);
    tv.setText(String.valueOf(mVolume));
    // Set up Button to increase the volume
    final Button upButton = (Button) findViewById(R.id.button2);
    upButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // Play key click sound
            mAudioManager.playSoundEffect(AudioManager.FX_KEY_CLICK);
            if (mVolume < mVolumeMax) {
                mVolume += 2;
                tv.setText(String.valueOf(mVolume));
            }
        }
    });
    // // Set up Button to decrease the volume
    final Button downButton = (Button) findViewById(R.id.button1);
    downButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // Play key click sound
            mAudioManager.playSoundEffect(AudioManager.FX_KEY_CLICK);
            if (mVolume > mVolumeMin) {
                mVolume -= 2;
                tv.setText(String.valueOf(mVolume));
            }
        }
    });
    final Button playButton = (Button) findViewById(R.id.button3);
    // Disable the Play Button so user can't click it before sounds are
    // ready
    playButton.setEnabled(false);
    // Create a SoundPool
    mSoundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
    // Load bubble popping sound into the SoundPool
    mSoundId = mSoundPool.load(this, R.raw.slow_whoop_bubble_pop, 1);
    // Set an OnLoadCompleteListener on the SoundPool
    mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {

        @Override
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            // If sound loading was successful enable the play Button
            if (0 == status) {
                playButton.setEnabled(true);
            } else {
                Log.i(TAG, "Unable to load sound");
                finish();
            }
        }
    });
    // Play the sound using a SoundPool
    playButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mCanPlayAudio)
                mSoundPool.play(mSoundId, (float) mVolume / mVolumeMax, (float) mVolume / mVolumeMax, 1, 0, 1.0f);
        }
    });
    // Request audio focus
    int result = mAudioManager.requestAudioFocus(afChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
    // Set to true if app has audio foucs
    mCanPlayAudio = AudioManager.AUDIOFOCUS_REQUEST_GRANTED == result;
}
Also used : Button(android.widget.Button) OnLoadCompleteListener(android.media.SoundPool.OnLoadCompleteListener) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) SoundPool(android.media.SoundPool) TextView(android.widget.TextView) View(android.view.View)

Aggregations

SoundPool (android.media.SoundPool)16 ContentResolver (android.content.ContentResolver)5 IntentFilter (android.content.IntentFilter)5 LockPatternUtils (com.android.internal.widget.LockPatternUtils)5 KeyguardDisplayManager (com.android.keyguard.KeyguardDisplayManager)5 Uri (android.net.Uri)2 View (android.view.View)2 Test (org.junit.Test)2 Config (org.robolectric.annotation.Config)2 Intent (android.content.Intent)1 MediaPlayer (android.media.MediaPlayer)1 OnPreparedListener (android.media.MediaPlayer.OnPreparedListener)1 OnLoadCompleteListener (android.media.SoundPool.OnLoadCompleteListener)1 OnClickListener (android.view.View.OnClickListener)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 EMServiceNotReadyException (com.easemob.exceptions.EMServiceNotReadyException)1 CameraHelper (com.juns.wechat.chat.utils.CameraHelper)1 LuaTable (org.luaj.vm2.LuaTable)1 LuaValue (org.luaj.vm2.LuaValue)1