Here you can find the source of addSoundFile(Context context, int resId, SoundAttributes attributes)
public static synchronized void addSoundFile(Context context, int resId, SoundAttributes attributes)
/**/*from w w w. j a va2 s. c o m*/ * Copyright 2010 The University of Nottingham * * This file is part of GenericAndroidClient. * * GenericAndroidClient is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GenericAndroidClient is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with GenericAndroidClient. If not, see <http://www.gnu.org/licenses/>. * */ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import android.content.Context; import android.media.AudioManager; import android.media.SoundPool; import android.util.Log; public class Main{ private static final int MAX_STREAMS = 4; /** singleton application sound poool */ private static SoundPool soundPool; /** map of sound resource id to sound id */ private static Map<Integer, Integer> resourceToSound = new HashMap<Integer, Integer>(); /** attributes by resource id */ private static Map<Integer, SoundAttributes> resourceToAttributes = new HashMap<Integer, SoundAttributes>(); /** add audio files specified by resource ids to pool */ public static synchronized void addSoundFile(Context context, int resId, SoundAttributes attributes) { init(); // default "prioirity" = 1 (future compat.) if (!resourceToSound.containsKey(resId)) resourceToSound.put(resId, soundPool.load(context, resId, 1)); resourceToAttributes.put(resId, attributes); } public static synchronized void init() { if (soundPool == null) soundPool = new SoundPool(MAX_STREAMS, AudioManager.STREAM_MUSIC, 0); } }