当前位置: 首页>>代码示例>>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;未经允许,请勿转载。