當前位置: 首頁>>代碼示例>>Java>>正文


Java SoundPool.setOnLoadCompleteListener方法代碼示例

本文整理匯總了Java中android.media.SoundPool.setOnLoadCompleteListener方法的典型用法代碼示例。如果您正苦於以下問題:Java SoundPool.setOnLoadCompleteListener方法的具體用法?Java SoundPool.setOnLoadCompleteListener怎麽用?Java SoundPool.setOnLoadCompleteListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.media.SoundPool的用法示例。


在下文中一共展示了SoundPool.setOnLoadCompleteListener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: FeedbackController

import android.media.SoundPool; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:google,項目名稱:brailleback,代碼行數:29,代碼來源:FeedbackController.java

示例2: soundPlay

import android.media.SoundPool; //導入方法依賴的package包/類
/**
 * 播放一個鈴聲
 *
 * @param context
 * @param resId   音樂資源ID
 */
public static void soundPlay(Context context, int resId) {
    if (playSound) {
        playCount = 0;
        replease();
        AudioManager am = (AudioManager) context
                .getSystemService(Context.AUDIO_SERVICE);// 實例化
        int audioMaxVolum = am.getStreamMaxVolume(AudioManager.STREAM_SYSTEM);// 音效最大值
        am.setStreamVolume(AudioManager.STREAM_SYSTEM, audioMaxVolum,
                AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
        float audioCurrentVolum = am
                .getStreamVolume(AudioManager.STREAM_SYSTEM);
        volumnRatio = audioCurrentVolum / audioMaxVolum;
        soundPool = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
        soundid = soundPool.load(context, resId, 1);
        soundPool.setOnLoadCompleteListener(new LoadCompleteListener());

    }
}
 
開發者ID:baby2431,項目名稱:LemonUtils,代碼行數:25,代碼來源:SoundPoolUtil.java

示例3: initSoundPool

import android.media.SoundPool; //導入方法依賴的package包/類
public void initSoundPool(){
	soundPool=new SoundPool(3, AudioManager.STREAM_MUSIC, 100); 
	soundPool.setOnLoadCompleteListener(this);
	try{
	for(int i=1;i<=Common.roma.length;++i){
		AssetFileDescriptor afd=getAssets().openFd("voices/"+Common.roma[i-1]+".wav");
		hm.put(i, soundPool.load(afd, 1));
	}
	}
	catch(Exception e){
		
	}
	
}
 
開發者ID:limitfan,項目名稱:Simple-Japanese-Gojuon,代碼行數:15,代碼來源:ActSeion.java

示例4: customShutterSound

import android.media.SoundPool; //導入方法依賴的package包/類
@SuppressLint("NewApi")
	public void customShutterSound() {
		try {
			if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
				CameraInfo cameraInfo = new CameraInfo();
				Camera.getCameraInfo(currentCamera, cameraInfo);
				if (cameraInfo.canDisableShutterSound) {
					mCamera.enableShutterSound(false);
				}

				final SoundPool soundPool = new SoundPool(1,
						AudioManager.STREAM_MUSIC, 0);
//				final int soundID = soundPool.load(mContext,
//						R.raw.shootsound, 1);
				final int soundID = 0; //先頂著

				final AudioManager mgr = (AudioManager) mContext
						.getSystemService(Context.AUDIO_SERVICE);
				float streamVolumeCurrent = mgr
						.getStreamVolume(AudioManager.STREAM_MUSIC);
				float streamVolumeMax = mgr
						.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
				final float volume = streamVolumeCurrent / streamVolumeMax;

				soundPool.setOnLoadCompleteListener(
						new SoundPool.OnLoadCompleteListener() {
							@Override
							public void onLoadComplete(SoundPool arg0,
													   int arg1, int arg2) {
								soundPool.play(soundID, volume, volume, 0, 0, 1f);
							}
						});
			}
		} catch (Exception e) {
			Log.e(TAG, e.toString());
		}
	}
 
開發者ID:orangecoder,項目名稱:VideoRecord,代碼行數:38,代碼來源:MyCameraManager.java

示例5: playViaSoundPool

import android.media.SoundPool; //導入方法依賴的package包/類
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.");
			}
		}
	});
}
 
開發者ID:imknown,項目名稱:IMKBaseFrameworkLibrary,代碼行數:41,代碼來源:MusicMediaPlayerUtil.java

示例6: setup

import android.media.SoundPool; //導入方法依賴的package包/類
private void setup() {
    // AudioManager audio settings for adjusting the volume
    mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    mActualVolume = (float) mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    mMaxVolume = (float) mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    mVolume = mActualVolume / mMaxVolume;

    // Load the sounds
    int srcQualityNotUsed = 0;
    mSoundPool = new SoundPool(MAX_SIMULTANEOUS_SOUNDS, AUDIO_STREAM_TYPE, srcQualityNotUsed);
    mSoundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
        @Override
        public void onLoadComplete(SoundPool soundPool, int soundId, int status) {
            final int SUCCESS = 0;
            if (status == SUCCESS)
                mTypeIsLoadedMap.put(soundId, true);

            if (++soundsLoaded >= Type.values().length)
                resourceLoadingFinished = true;

            Log.d("SE", String.format("soundsLoaded=%d, values=%s, Type.values().length= %d, resourceLoadingFinished=%b",
                                      soundsLoaded, Type.values(), Type.values().length, resourceLoadingFinished));
        }
    });

    loadSound(Type.FLIP, R.raw.flip);
    loadSound(Type.NO_MATCH, R.raw.no_match);
    loadSound(Type.MATCH, R.raw.match);
    loadSound(Type.WIN, R.raw.win);
    loadSound(Type.START, R.raw.start);
}
 
開發者ID:TampaBayAndroid,項目名稱:Memory,代碼行數:32,代碼來源:SoundsEffects.java

示例7: loadSoundPool

import android.media.SoundPool; //導入方法依賴的package包/類
private void loadSoundPool() {
	soundpool = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
	soundpool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
		
		@Override
		public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
			loaded = true;
		}
	});
	AssetFileDescriptor fd = getResources().openRawResourceFd(R.raw.tone800hz);
	dotSound = soundpool.load(fd.getFileDescriptor(), fd.getStartOffset(), (long)(fd.getLength() * 0.1), 1);
	dashSound = soundpool.load(fd.getFileDescriptor(), fd.getStartOffset(), (long)(fd.getLength() * 0.3), 1);
}
 
開發者ID:agwells,項目名稱:dotdash-keyboard-android,代碼行數:14,代碼來源:DotDashIMEService.java

示例8: SoundPoolPlayer

import android.media.SoundPool; //導入方法依賴的package包/類
public SoundPoolPlayer(Context context) {
    mContext = context;

    mSoundIDToPlay = ID_NOT_LOADED;

    mSoundPool = new SoundPool(NUM_SOUND_STREAMS, getAudioTypeForSoundPool(), 0);
    mSoundPool.setOnLoadCompleteListener(this);

    mSoundIDs = new int[SOUND_RES.length];
    mSoundIDReady = new boolean[SOUND_RES.length];
    for (int i = 0; i < SOUND_RES.length; i++) {
        mSoundIDs[i] = mSoundPool.load(mContext, SOUND_RES[i], 1);
        mSoundIDReady[i] = false;
    }
}
 
開發者ID:jameliu,項目名稱:Camera2,代碼行數:16,代碼來源:SoundClips.java

示例9: onResume

import android.media.SoundPool; //導入方法依賴的package包/類
@Override
public void onResume() {

    StudyTimer timer = StudyTimer.getInstance();
    timer.start(getActivity(), StudyTimer.StudyType.LearnDouble);

    soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, SRC_QUALITY);
    soundPool.setOnLoadCompleteListener(this);

    super.onResume();
}
 
開發者ID:suragch,項目名稱:aePronunciation,代碼行數:12,代碼來源:LearnDoubleDialogFragment.java

示例10: onResume

import android.media.SoundPool; //導入方法依賴的package包/類
@Override
public void onResume() {

    if (videoView != null) {
        videoView.seekTo(1);
    }

    soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, SRC_QUALITY);
    soundPool.setOnLoadCompleteListener(this);

    super.onResume();
}
 
開發者ID:suragch,項目名稱:aePronunciation,代碼行數:13,代碼來源:LearnSingleFragment.java

示例11: onResume

import android.media.SoundPool; //導入方法依賴的package包/類
@Override
protected void onResume() {

    StudyTimer timer = StudyTimer.getInstance();
    if (testMode == SoundMode.Single) {
        timer.start(this, StudyTimer.StudyType.TestSingle);
    } else if (testMode == SoundMode.Double) {
        timer.start(this, StudyTimer.StudyType.TestDouble);
    }

    soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, SRC_QUALITY);
    soundPool.setOnLoadCompleteListener(this);

    super.onResume();
}
 
開發者ID:suragch,項目名稱:aePronunciation,代碼行數:16,代碼來源:TestResultsActivity.java

示例12: onResume

import android.media.SoundPool; //導入方法依賴的package包/類
@Override
public void onResume() {

    StudyTimer timer = StudyTimer.getInstance();
    if (testMode == SoundMode.Single) {
        timer.start(getActivity(), StudyTimer.StudyType.TestSingle);
    } else if (testMode == SoundMode.Double) {
        timer.start(getActivity(), StudyTimer.StudyType.TestDouble);
    }

    soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, SRC_QUALITY);
    soundPool.setOnLoadCompleteListener(this);

    super.onResume();
}
 
開發者ID:suragch,項目名稱:aePronunciation,代碼行數:16,代碼來源:TestContentFragment.java

示例13: onResume

import android.media.SoundPool; //導入方法依賴的package包/類
@Override
protected void onResume() {
    soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, SRC_QUALITY);
    soundPool.setOnLoadCompleteListener(this);

    super.onResume();
}
 
開發者ID:suragch,項目名稱:aePronunciation,代碼行數:8,代碼來源:HistoryTestDetailsActivity.java

示例14: SoundManager

import android.media.SoundPool; //導入方法依賴的package包/類
/**
 * Private constructor for singleton
 */
private SoundManager() {
    _soundPool = new SoundPool(MAX_STREAMS, AudioManager.STREAM_MUSIC, 0);
    _soundPool.setOnLoadCompleteListener(this);

    _streamIdMap = new HashMap<>();
}
 
開發者ID:mediamonks,項目名稱:tilt-game-android,代碼行數:10,代碼來源:SoundManager.java

示例15: onResume

import android.media.SoundPool; //導入方法依賴的package包/類
@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;

}
 
開發者ID:aporter,項目名稱:umd-android-labs,代碼行數:31,代碼來源:BubbleActivity.java


注:本文中的android.media.SoundPool.setOnLoadCompleteListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。