Example usage for android.media SoundPool SoundPool

List of usage examples for android.media SoundPool SoundPool

Introduction

In this page you can find the example usage for android.media SoundPool SoundPool.

Prototype

public SoundPool(int maxStreams, int streamType, int srcQuality) 

Source Link

Document

Constructor.

Usage

From source file:Main.java

public static synchronized void init() {
    if (soundPool == null)
        soundPool = new SoundPool(MAX_STREAMS, AudioManager.STREAM_MUSIC, 0);
}

From source file:capstone.se491_phm.Alarm.java

@SuppressWarnings("deprecation")
public static void siren(Context context) {
    if (null == pool) {
        pool = new SoundPool(5, AudioManager.STREAM_ALARM, 0);
    }//from  w w w . j av  a 2  s  .  c o m
    if (-1 == id) {
        id = pool.load(context.getApplicationContext(), R.raw.alarm, 1);
        loudest(context, AudioManager.STREAM_ALARM);
        pool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
            @Override
            public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                soundPool.play(id, 1.0f, 1.0f, 1, 3, 1.0f);
            }
        });
        loudest(context, AudioManager.STREAM_ALARM);
        pool.play(id, 1.0f, 1.0f, 1, 3, 1.0f);
    } else {
        loudest(context, AudioManager.STREAM_ALARM);
        pool.play(id, 1.0f, 1.0f, 1, 3, 1.0f);
    }
}

From source file:MainActivity.java

@SuppressWarnings("deprecation")
private void createSoundPooolOld() {
    mSoundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
}

From source file:com.intel.xdk.notification.Notification.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    //get convenience reference to activity
    activity = cordova.getActivity();//  w w w  . j a  va2s.  c o m

    //init sounds
    soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);

    //this is needed so that the sound plays the first time
    soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            if (beepCount != -1 && soundPool == Notification.this.soundPool && sampleId == SOUND_BEEP
                    && status == 0) {
                beep(beepCount);
            }
        }
    });

    //SOUND_BEEP = soundPool.load(activity, R.raw.beep, 1);
    SOUND_BEEP = soundPool.load(activity,
            activity.getResources().getIdentifier("xdkbeep", "raw", activity.getPackageName()), 1);
}

From source file:com.vrjco.v.demo.MainActivity.java

private void initialize_Layout() {
    tvlat = (TextView) findViewById(R.id.tv_lat);
    tvlongi = (TextView) findViewById(R.id.tv_longi);
    tvtestlat = (TextView) findViewById(R.id.test_lat);
    tvtestlongi = (TextView) findViewById(R.id.test_longi);
    tvSameLocation = (TextView) findViewById(R.id.check_loc);
    bStart = (Button) findViewById(R.id.bstart);
    bTest = (Button) findViewById(R.id.btest);
    test_is_set = false;/*  w  ww. j  av  a  2s.c o m*/
    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    logLocationListener = new LogLocationListener();
    testLocationListener = new TestLocationListener();
    handler = new Handler(getMainLooper());
    //noinspection deprecation
    sp = new SoundPool(1, AudioManager.STREAM_ALARM, 0);
    beep_sound = sp.load(getApplicationContext(), R.raw.beep, 1);
}

From source file:hyplink.net.pot.GameActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // load logic
    grid = new Grid();
    // load controller
    controller = new SwipeController(this);
    // load data//from w  w  w  . ja  va2s  .  c  om
    gamePreferences = new GamePreferences(this);
    // load sound
    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    soundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
    // load view
    setOrientation();
    StartAppSDK.init(this, "108710732", "208747074", true);
    StartAppAd.showSplash(this, savedInstanceState);
    setContentView(R.layout.game);
    loadView();
    // load animation
    animation = AnimationUtils.loadAnimation(this, R.anim.cell_animation);
}

From source file:com.kentli.cycletrack.RecordingService.java

@Override
public void onCreate() {
    super.onCreate();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        AudioAttributes attributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_GAME)
                .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build();

        soundpool = new SoundPool.Builder().setAudioAttributes(attributes).build();
    } else {/*from   w ww  .  ja v a 2  s  . c om*/
        soundpool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
    }
    soundpool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
        @Override
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            soundPool.play(sampleId, 1.0f, 1.0f, 0, 0, 1.0f);
        }
    });
    bikebell = soundpool.load(this.getBaseContext(), R.raw.bikebell, 1);
}

From source file:nl.vincentketelaars.mexen.activities.RollDice.java

/** Called when the activity is first created. */
@Override/*w ww.j  a  v  a2s .  c o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Make title bar icon clickable, and go home
    getActionBar().setDisplayHomeAsUpEnabled(true);

    setVolumeControlStream(AudioManager.STREAM_MUSIC); // User can modify music volume
    soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
    soundMap = new SparseIntArray();
    soundMap.put(R.raw.roll, soundPool.load(this, R.raw.roll, 1)); // Note: If load returns 0 it failed

    activity = this;

    currentGame = new Game(currentMode);

    MGDbHelper = new MexGameDbHelper(this);

    sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    getActionBar().setTitle(String.format(getResources().getString(R.string.roll_activity_name), numDice()));
}

From source file:com.intel.xdk.player.Player.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    //get convenience reference to activity
    activity = cordova.getActivity();/*from  w ww.  jav  a 2s.c o m*/

    //get the current url
    final CordovaWebView wv = webView;
    activity.runOnUiThread(new Runnable() {
        public void run() {
            currentUrl = wv.getUrl();
        }
    });

    //turn on remote debugging
    // activity.runOnUiThread(new Runnable() {
    //     public void run() {
    //         if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    //          try {
    //              Method m = WebView.class.getMethod("setWebContentsDebuggingEnabled", boolean.class);
    //              m.invoke(WebView.class, true);
    //          } catch (Exception e) {
    //              // TODO Auto-generated catch block
    //              e.printStackTrace();
    //          }
    //         }
    //     }
    // });

    soundPool = new SoundPool(30, AudioManager.STREAM_MUSIC, 100);
    soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            soundLoaded(sampleId, status);
        }
    });
    hasLoadSoundCallback = true;
}

From source file:com.everyplay.android.everyplayrecord.EveryplayRecordActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create a GLSurfaceView instance and set it
    // as the ContentView for this Activity
    mGLView = new EveryplayRecordSurfaceView(this);
    setContentView(mGLView);/* w  w w . j av  a 2s  . co  m*/

    buttons = new LinearLayout(this);
    buttons.setOrientation(LinearLayout.VERTICAL);
    if (!USE_EVERYPLAY_AUDIO_BOARD) {
        addButton("Everyplay", "everyplay");
        addButton("Start recording", "rec");
        Button playLastRecording = addButton("Play last recording", "play_last_recording");
        playLastRecording.setVisibility(View.GONE);

        addButton("Test video playback", "test_video_playback");
        addButton("Show sharing modal", "sharing_modal");

        Button hudRecord = addButton("HUD record off", "hud_record");
        hudRecord.setVisibility(View.GONE);

        stream1 = new EveryplayRecordAudioGenerator(5);
        stream1.play();
        streamActive = stream1;
    } else {
        addButton("Play song #1", "play1_a");
        addButton("Unload song #1", "unload1_a");
        addButton("Pause song", "pause_a");
        addButton("Resume song", "resume_a");
        addButton("Rewind song", "rewind_a");
        addButton("Stop song", "stop_a");

        this.addContentView(buttons, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        buttons = new LinearLayout(this);
        buttons.setOrientation(LinearLayout.VERTICAL);
        buttons.setX(400);

        addButton("Play song #2", "play2_a");
        addButton("Unload song #2", "unload2_a");
        addButton("Effect #1", "effect1_a");
        addButton("Effect #2", "effect2_a");
        addButton("Start recording", "rec");
        addButton("Play last recording", "play_last_recording");

        soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
        sound_pew = soundPool.load(this, R.raw.pew, 1);
        sound_pow = soundPool.load(this, R.raw.pow, 1);
    }

    this.addContentView(buttons, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    init();
}