Java 类android.media.SoundPool.OnLoadCompleteListener 实例源码

项目:boohee_v5.6    文件:MQSoundPoolManager.java   
public void playSound(@RawRes final int resId) {
    if (this.mSoundSourceMap != null) {
        if (this.mSoundSourceMap.containsKey(Integer.valueOf(resId))) {
            play(((Integer) this.mSoundSourceMap.get(Integer.valueOf(resId))).intValue());
            return;
        }
        this.mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
            public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                if (status == 0) {
                    MQSoundPoolManager.this.mSoundSourceMap.put(Integer.valueOf(resId),
                            Integer.valueOf(sampleId));
                    MQSoundPoolManager.this.play(sampleId);
                }
            }
        });
        this.mSoundPool.load(this.mContext.getApplicationContext(), resId, 1);
    }
}
项目:brailleback    文件:FeedbackController.java   
/**
 * Constructs and initializes a new feedback controller.
 */
public FeedbackController(Context context) {
    mContext = context;
    mResources = context.getResources();
    mVibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
    mSoundPool = new SoundPool(NUMBER_OF_CHANNELS, DEFAULT_STREAM, 1);
    mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
        @Override
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            if (status == 0) {
                synchronized (mPostLoadPlayables) {
                    if (mPostLoadPlayables.contains(sampleId)) {
                        soundPool.play(
                                sampleId, DEFAULT_VOLUME, DEFAULT_VOLUME, 1, 0, DEFAULT_RATE);
                        mPostLoadPlayables.remove(Integer.valueOf(sampleId));
                    }
                }
            }
        }
    });
    mHandler = new Handler();

    mResourceIdToSoundMap.clear();
    mResourceIdToVibrationPatternMap.clear();
    MidiUtils.purgeMidiTempFiles(context);
}
项目:TrueTone    文件:SoundManager.java   
public void playSequence(final boolean loop) {
        int midiValue = 0;
        int velocity = 0;
        int instrument = 0;
        String fileName = "dyn_" + midiValue + ".mid";
//        MidiFile.writeNoteFile(midiValue, velocity, fileName, MainActivity.config.tempo.getTempoEvent());
//        MidiFile.writeSingleNoteFile(midiValue,instrument, velocity, fileName, MainActivity.config.tempo.getTempoEvent());
        lastSequenceId = sequenceSoundPool.load(FileManager.getInstance().INTERNAL_PATH + "sequence.mid", 1);
        sequenceSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
            @Override
            public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                sequenceSoundPool.play(lastSequenceId, 1, 1, 0, (loop ? -1 : 0), 1);
            }
        });

        try {
            mediaPlayer.reset();
            mediaPlayer.setDataSource(FileManager.getInstance().EXTERNAL_PATH + "sequence.mid");
            mediaPlayer.setLooping(loop);
            mediaPlayer.prepare();
            mediaPlayer.start();
        } catch (Exception e) {
            HLog.e("Media Player Failure");
            e.printStackTrace();
        }
    }
项目:talkback    文件:FeedbackControllerApp.java   
@Override
public void playAuditory(int resId, final float rate, float volume) {
    if (!mAuditoryEnabled || resId == 0) return;
    final float adjustedVolume = volume * mVolumeAdjustment;
    int soundId = mSoundIds.get(resId);

    if (soundId != 0) {
        new EarconsPlayTask(mSoundPool, soundId, adjustedVolume, rate).execute();
    } else {
        // The sound could not be played from the cache. Start loading the sound into the
        // SoundPool for future use, and use a listener to play the sound ASAP.
        mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
            @Override
            public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                if(sampleId !=0) {
                    new EarconsPlayTask(mSoundPool, sampleId, adjustedVolume, rate).execute();
                }
            }
        });
        mSoundIds.put(resId, mSoundPool.load(mContext, resId, 1));
    }
}
项目:bither-android    文件:PlaySound.java   
public static void play(final int soundId,
        final PlaySoundCompletionListener playSoundCompletionListener) {
    if (sounds.get(soundId) != null) {
        int soundID1 = sounds.get(soundId);
        beginPlay(soundID1, playSoundCompletionListener);
    } else {
        synchronized (sounds) {
            final int soundIDOfPool = soundPool.load(
                    BitherApplication.mContext, soundId, 1);
            soundPool
                    .setOnLoadCompleteListener(new OnLoadCompleteListener() {
                        @Override
                        public void onLoadComplete(SoundPool arg0,
                                int arg1, int arg2) {
                            if (arg1 == soundIDOfPool) {
                                beginPlay(soundIDOfPool,
                                        playSoundCompletionListener);
                            }
                        }
                    });
            LogUtil.d("record", "load:" + soundId);
            sounds.put(soundId, soundIDOfPool);
        }
    }
}
项目: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);
}
项目:AndroidEskwela    文件:BubbleActivity.java   
/** State where the UI becomes visible and the user can start interacting.*/
    @Override
    protected void onResume() {
        super.onResume();
//      log("onResume");        

        // Manage bubble popping sound. Use AudioManager.STREAM_MUSIC as stream type
        mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);

        mStreamVolume = (float) mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC) / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); //divide by is the forward.

        mSoundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0); //0 is currently not implemented by Google.

        mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
            @Override
            public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                if (status == 0) {
//                  log("onLoadComplete sound");                    
                    setupGestureDetector();
                }
            }
        });

        mSoundID = mSoundPool.load(this, R.raw.bubble_pop, 1); //load the sound from res/raw/bubble_pop.wav     
    }
项目:IMKBaseFrameworkLibrary    文件:MusicMediaPlayerUtil.java   
public static void playViaSoundPool(Context context, final int resId) {
    // AudioAttributes.Builder attrBuilder = new AudioAttributes.Builder();
    // attrBuilder.setLegacyStreamType(AudioManager.STREAM_NOTIFICATION);
    // attrBuilder.setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT);
    // attrBuilder.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION);
    //
    // SoundPool.Builder spBuilder = new SoundPool.Builder();
    // spBuilder.setMaxStreams(2);
    // spBuilder.setAudioAttributes(attrBuilder.build());
    //
    // SoundPool sp21 = spBuilder.build();

    int maxStreams = 5, streamType = AudioManager.STREAM_NOTIFICATION, srcQuality = 0;
    @SuppressWarnings("deprecation")
    final SoundPool sp20 = new SoundPool(maxStreams, streamType, srcQuality);

    int priority = 1;
    final int soundId = sp20.load(context, resId, priority);

    // soundID : a soundID returned by the load() function
    // leftVolume : left volume value (range = 0.0 to 1.0), 左声道
    // rightVolume : right volume value (range = 0.0 to 1.0), 右声道
    // priority : stream priority (0 = lowest priority), 优先级
    // loop : loop mode (0 = no loop, -1 = loop forever), 循环与否
    // rate : playback rate (1.0 = normal playback, range 0.5 to 2.0), 播放返回的速度
    final float leftVolume = 1, rightVolume = 1;
    final int playPriority = 0, loop = 0;
    final float rate = 1.0F;

    sp20.setOnLoadCompleteListener(new OnLoadCompleteListener() {
        @Override
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            int streamID = sp20.play(soundId, leftVolume, rightVolume, playPriority, loop, rate);

            if (streamID == 0 || status != 0) {
                LogUtil.e("Play sound " + resId + " fail.");
            }
        }
    });
}
项目:umd-android-labs    文件:BubbleActivity.java   
@Override
protected void onResume() {
    super.onResume();

    // Manage bubble popping sound
    // Use AudioManager.STREAM_MUSIC as stream type

    mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);

    mStreamVolume = (float) mAudioManager
            .getStreamVolume(AudioManager.STREAM_MUSIC)
            / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);

    // Make a new SoundPool, allowing up to 10 streams
    mSoundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);

    // TODO - Set a SoundPool OnLoadCompletedListener that calls
    // setupGestureDetector()
    mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
        @Override
        public void onLoadComplete(SoundPool soundPool, int sampleId,
                int status) {

           }
    });

    // TODO - Load the sound from res/raw/bubble_pop.wav
       mSoundID = 0;

}
项目:android_coursera_1    文件:BubbleActivity.java   
@Override
protected void onResume() {
    super.onResume();

    // Manage bubble popping sound
    // Use AudioManager.STREAM_MUSIC as stream type

    mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);

    mStreamVolume = (float) mAudioManager
            .getStreamVolume(AudioManager.STREAM_MUSIC)
            / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);

    // TODO - make a new SoundPool, allowing up to 10 streams 
    mSoundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);

    // TODO - set a SoundPool OnLoadCompletedListener that calls setupGestureDetector()
    mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
        @Override
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {

            if (0 == status) {
                    setupGestureDetector();
            }
        }
    });

    // TODO - load the sound from res/raw/bubble_pop.wav
    mSoundID = mSoundPool.load(this, R.raw.bubble_pop, 1);

}
项目:android-002    文件:BubbleActivity.java   
@Override
protected void onResume() {
    super.onResume();
    Log.d(TAG, "In onResume()...");

    // Manage bubble popping sound
    // Use AudioManager.STREAM_MUSIC as stream type

    mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);

    mStreamVolume = (float) mAudioManager
            .getStreamVolume(AudioManager.STREAM_MUSIC)
            / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);

    // TODO - make a new SoundPool, allowing up to 10 streams
    mSoundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);

    // TODO - set a SoundPool OnLoadCompletedListener that calls
    // setupGestureDetector()
    mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {

        @Override
        public void onLoadComplete(SoundPool soundPool, int sampleId,
                int status) {
            Log.d(TAG, "SoundPool has finished loading sound " + sampleId);
            setupGestureDetector();
        }
    });

    // TODO - load the sound from res/raw/bubble_pop.wav
    mSoundID = mSoundPool.load(this, R.raw.bubble_pop, 1);
}
项目:crazyflie-android-client    文件:MainActivity.java   
private void initializeSounds() {
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
    // Load sounds
    mSoundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
    mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
        @Override
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            mLoaded = true;
        }
    });
    mSoundConnect = mSoundPool.load(this, R.raw.proxima, 1);
    mSoundDisconnect = mSoundPool.load(this, R.raw.tejat, 1);
}
项目:SimpleAndroidGLPiano    文件:GL2JNIActivity.java   
@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    mView = new GL2JNIView(getApplication());
    mView.setOnTouchListener(this);
    Display display = getWindowManager().getDefaultDisplay();
    display.getSize(size);
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
    lib.setContext(this);
    lib.setSoundPool(new SoundPool(10, AudioManager.STREAM_MUSIC, 0));
    lib.getSoundPool().setOnLoadCompleteListener(new OnLoadCompleteListener() {
        @Override
        public void onLoadComplete(SoundPool soundPool, int sampleId,
                int status) {
            lib.setLoaded(true);
        }
    });
    lib.setSoundIDA(lib.getSoundPool().load(this, R.raw.a, 1));
    lib.setSoundIDB(lib.getSoundPool().load(this, R.raw.b, 1));
    lib.setSoundIDG(lib.getSoundPool().load(this, R.raw.g, 1));
    lib.setSoundIDCSharp(lib.getSoundPool().load(this, R.raw.cs, 1));
    lib.setSoundIDC(lib.getSoundPool().load(this, R.raw.cs, 1));
    lib.setSoundIDD(lib.getSoundPool().load(this, R.raw.d, 1));
    lib.setSoundIDE(lib.getSoundPool().load(this, R.raw.e, 1));
    lib.setSoundIDFSharp(lib.getSoundPool().load(this, R.raw.fs, 1));
    lib.setAudioManager((AudioManager) getSystemService(AUDIO_SERVICE));
    setContentView(mView);
}