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


Java SoundPool.load方法代碼示例

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


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

示例1: registerWithPlayer

import android.media.SoundPool; //導入方法依賴的package包/類
public void registerWithPlayer(SoundPool player)
{
    try
    {
        if(fd != null)
        {
            soundId = player.load(fd, 1);
            fd.close();
        }
        else
        {
            soundId = player.load(res, 1);
        }
    }
    catch (IOException e)
    {
        Log.e("error loading audio files", e);
    }
}
 
開發者ID:hcmlab,項目名稱:ssj,代碼行數:20,代碼來源:AudioAction.java

示例2: loadSound

import android.media.SoundPool; //導入方法依賴的package包/類
public void loadSound(){
    soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
    try {
        //Create objects of the 2 required classes
        AssetManager assetManager = getAssets();
        AssetFileDescriptor descriptor;

        //create our three fx in memory ready for use
        descriptor = assetManager.openFd("sample1.ogg");
        sample1 = soundPool.load(descriptor, 0);

        descriptor = assetManager.openFd("sample4.ogg");
        sample4 = soundPool.load(descriptor, 0);


    } catch (IOException e) {
        //catch exceptions here
    }
}
 
開發者ID:PacktPublishing,項目名稱:Android-Game-Programming,代碼行數:20,代碼來源:GameActivity.java

示例3: soundPlay

import android.media.SoundPool; //導入方法依賴的package包/類
/**
 * 播放一個鈴聲
 *
 * @param context
 * @param resId   音樂資源ID
 * @param count   循環次數
 */
public static void soundPlay(Context context, int resId, int count) {
    if (playSound) {
        playCount = count;
        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,代碼行數:26,代碼來源:SoundPoolUtil.java

示例4: MetronomeManager

import android.media.SoundPool; //導入方法依賴的package包/類
/**
 * Ctor for the metronome manager class.
 * 
 * @param context
 *            The context used for getting the sound files from the assest.
 */
public MetronomeManager(Context context)
{
	// Create a new instance of the media player to play the ticks.
	m_cSoundPlayer =
			new SoundPool(2, AudioManager.STREAM_MUSIC, 0);

	// Initialize a new timer.
	m_beatTimer = new Timer();

	// Load the tick sound.
	m_nTickSoundId =
			m_cSoundPlayer.load(context,
					R.raw.metronome_tick, 1);

	// Load the tock sound.
	m_nTockSoundId =
			m_cSoundPlayer.load(context,
					R.raw.metronome_tock, 1);
}
 
開發者ID:netanelkl,項目名稱:guitar_guy,代碼行數:26,代碼來源:MetronomeManager.java

示例5: initSound

import android.media.SoundPool; //導入方法依賴的package包/類
private void initSound() {
    mSoundPool = new SoundPool(50, AudioManager.STREAM_SYSTEM, 5);
    try {
        mSoundPool.load(getContext(), R.raw.wheelpickerkeypress, 1);
    } catch (Exception e) {
    }
}
 
開發者ID:devilist,項目名稱:RecyclerWheelPicker,代碼行數:8,代碼來源:RecyclerWheelPicker.java

示例6: createOldSoundPool

import android.media.SoundPool; //導入方法依賴的package包/類
/**
 * SoundPool creator with the old constructor for devices with less than API 21
 */
@SuppressWarnings("deprecation")
private void createOldSoundPool() {
    Log.d(this.getClass().getSimpleName(), "old soundpool constructor");

    soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
    correctSound = soundPool.load(this, R.raw.correct_sound, 1);
    wrongSound = soundPool.load(this, R.raw.wrong_sound, 1);
}
 
開發者ID:AythaE,項目名稱:ESDLA-Quiz,代碼行數:12,代碼來源:GameActivity.java

示例7: onCreate

import android.media.SoundPool; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_decision_maker);

	sounds = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
	popSoundId = sounds.load(DecisionMakerActivity.this, R.raw.pop, 1);
	glassSoundId = sounds.load(DecisionMakerActivity.this, R.raw.glass, 1);

	// TODO Send time interval as activity parameter.
	timer.schedule(new TimerTask() {
		@Override
		public void run() {
			roll();
		}
	}, 0, 100);

	sectors[0] = (ImageView) findViewById(R.id.sector01);
	sectors[1] = (ImageView) findViewById(R.id.sector02);
	sectors[2] = (ImageView) findViewById(R.id.sector03);
	sectors[3] = (ImageView) findViewById(R.id.sector04);
	sectors[4] = (ImageView) findViewById(R.id.sector05);
	sectors[5] = (ImageView) findViewById(R.id.sector06);
	sectors[6] = (ImageView) findViewById(R.id.sector07);
	sectors[7] = (ImageView) findViewById(R.id.sector08);

	((Button) findViewById(R.id.roll))
			.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					randomSectorIndex = PRNG.nextInt(sectors.length);
					rollStartTime = System.currentTimeMillis();
					rollMode = true;
				}
			});
}
 
開發者ID:sdrausty,項目名稱:buildAPKsApps,代碼行數:37,代碼來源:DecisionMakerActivity.java

示例8: doAlarm

import android.media.SoundPool; //導入方法依賴的package包/類
private void doAlarm() {
	if (mCurrMInfo.isVibrate()){
		mVibrator.vibrate(1000);
	}
	if (mCurrMInfo.isRing()){
		SoundPool soundPool = new SoundPool(2, AudioManager.STREAM_SYSTEM, 5);
		soundPool.load(this, R.raw.ticket_alarm, 1);
		soundPool.play(1, 1, 1, 0, 0, 1);
	}
}
 
開發者ID:SShineTeam,項目名稱:Huochexing12306,代碼行數:11,代碼來源:BgdService2.java

示例9: loadSoundPool

import android.media.SoundPool; //導入方法依賴的package包/類
/**
 * Loads the audio specified by mediaPath into the given SoundPool and
 * returns the sound id.
 *
 * Note that if the mediaPath is a content URI or an URL, the audio must be
 * copied to a temp file and then loaded from there. This could have
 * performance implications.
 *
 * @param soundPool the SoundPool
 * @param form the Form
 * @param mediaPath the path to the media
 */
public static int loadSoundPool(SoundPool soundPool, Form form, String mediaPath)
    throws IOException {
  MediaSource mediaSource = determineMediaSource(form, mediaPath);
  switch (mediaSource) {
    case ASSET:
      return soundPool.load(getAssetsIgnoreCaseAfd(form,mediaPath), 1);

    case REPL_ASSET:
      return soundPool.load(replAssetPath(mediaPath), 1);

    case SDCARD:
      return soundPool.load(mediaPath, 1);

    case FILE_URL:
      return soundPool.load(fileUrlToFilePath(mediaPath), 1);

    case CONTENT_URI:
    case URL:
      File tempFile = cacheMediaTempFile(form, mediaPath, mediaSource);
      return soundPool.load(tempFile.getAbsolutePath(), 1);

    case CONTACT_URI:
      throw new IOException("Unable to load audio for contact " + mediaPath + ".");
  }

  throw new IOException("Unable to load audio " + mediaPath + ".");
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:40,代碼來源:MediaUtil.java

示例10: enterFeedback

import android.media.SoundPool; //導入方法依賴的package包/類
@Override
public void enterFeedback() throws SSJFatalException
{
	if (_evchannel_in == null || _evchannel_in.size() == 0)
	{
		throw new SSJFatalException("no input channels");
	}

	player = new SoundPool(4, AudioManager.STREAM_NOTIFICATION, 0);
	soundId = player.load(options.audioFile.get().value, 1);
}
 
開發者ID:hcmlab,項目名稱:ssj,代碼行數:12,代碼來源:AuditoryFeedback.java

示例11: onCreate

import android.media.SoundPool; //導入方法依賴的package包/類
@Override
public void onCreate() {
    // TODO Auto-generated method stub
    super.onCreate();
    resolver = getContentResolver();
    map = new HashMap<>();
    con = XmppTool.getInstance().getCon();
    user = SaveUserUtil.loadAccount(XmppService.this).getUser();
    pool = new SoundPool(10, AudioManager.STREAM_SYSTEM, 5);
    pool.load(this, R.raw.tishi, 1);
    vibrator = (Vibrator) getSystemService(Service.VIBRATOR_SERVICE);
    Log.i("service", "啟動服務......");

}
 
開發者ID:jiangzehui,項目名稱:xmpp,代碼行數:15,代碼來源:XmppService.java

示例12: GameView

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

  parent = (C2B) context;
  lastTarget = 0;
  score = 0;
  comboCount = 0;
  longestCombo = 0;
  lastRating = "";

  drawnTargets = new ArrayList<Target>();
  recordedTargets = new ArrayList<Target>();

  vibe = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);

  snd = new SoundPool(10, AudioManager.STREAM_SYSTEM, 0);
  missSfx = snd.load(context, R.raw.miss, 0);
  hitOkSfx = snd.load(context, R.raw.ok, 0);
  hitPerfectSfx = snd.load(context, R.raw.perfect, 0);

  innerPaint = new Paint();
  innerPaint.setColor(Color.argb(127, 0, 0, 0));
  innerPaint.setStyle(Paint.Style.FILL);
  borderPaint = new Paint();
  borderPaint.setStyle(Paint.Style.STROKE);
  borderPaint.setAntiAlias(true);
  borderPaint.setStrokeWidth(2);
  haloPaint = new Paint();
  haloPaint.setStyle(Paint.Style.STROKE);
  haloPaint.setAntiAlias(true);
  haloPaint.setStrokeWidth(4);

  Thread monitorThread = (new Thread(new Monitor()));
  monitorThread.setPriority(Thread.MIN_PRIORITY);
  monitorThread.start();
}
 
開發者ID:tgmarinho,項目名稱:apps-for-android,代碼行數:37,代碼來源:GameView.java

示例13: onCreate

import android.media.SoundPool; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC,0);
    try{
        //Create objects of the 2 required classes
        AssetManager assetManager = getAssets();
        AssetFileDescriptor descriptor;

        //create our three fx in memory ready for use
        descriptor = assetManager.openFd("sample1.ogg");
        sample1 = soundPool.load(descriptor, 0);

        descriptor = assetManager.openFd("sample2.ogg");
        sample2 = soundPool.load(descriptor, 0);


        descriptor = assetManager.openFd("sample3.ogg");
        sample3 = soundPool.load(descriptor, 0);


    }catch(IOException e){
        //catch exceptions here
    }

    //Make a button from each of the buttons in our layout
    Button button1 =(Button) findViewById(R.id.button);
    Button button2 =(Button) findViewById(R.id.button2);
    Button button3 =(Button) findViewById(R.id.button3);

    //Make each of them listen for clicks
    button1.setOnClickListener(this);
    button2.setOnClickListener(this);
    button3.setOnClickListener(this);


}
 
開發者ID:PacktPublishing,項目名稱:Android-Game-Programming,代碼行數:40,代碼來源:MainActivity.java

示例14: MediaController

import android.media.SoundPool; //導入方法依賴的package包/類
private MediaController() {
    try {
        sensorManager = (SensorManager) MainApp.CONTEXT.getSystemService(Context.SENSOR_SERVICE);
        proximitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
        soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
        soundEffectId = soundPool.load(MainApp.CONTEXT, R.raw.add, 1);
    } catch (Exception e) {
        Logger.e(TAG, "Sensor init error", e);
    }
}
 
開發者ID:jianliaoim,項目名稱:talk-android,代碼行數:11,代碼來源:MediaController.java

示例15: GameLogic

import android.media.SoundPool; //導入方法依賴的package包/類
public GameLogic(Context context, int ID) {
	blockMap = new BlockMap(context);
	blockMap.selectMap(ID);
	nowLevelID=ID;
	
	audio=new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
	audio_res=audio.load(context, R.raw.tick,1);
	initBlock();
}
 
開發者ID:VMatrices,項目名稱:CubeMatrix,代碼行數:10,代碼來源:GameLogic.java


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