2011-09-15 12 views
6

मुझे डीबग में चलाने पर सैकड़ों बार यह त्रुटि मिलती है, यह प्रोग्राम को प्रभावित नहीं करता है, लेकिन मैं इससे कैसे छुटकारा पा सकता हूं?एंड्रॉइड साउंडपूल हेपसाइज ओवरफ्लो

मैं जानता हूँ कि इसे वापस SoundPool के आधार पर पता लगाया जा सकता अन्य पदों

09-15 09 पर: 03: ०९.१९०: त्रुटि/AudioCache (34): ढेर आकार अतिप्रवाह! req आकार: 1052672, अधिकतम आकार: 1048576

+0

तो बस अपने ढेर आकार में वृद्धि – RoflcoptrException

+0

मुझे लगता है कि कैसे करते हो? – GideonKain

+0

http://viralpatel.net/blogs/2009/01/jvm-java-increase-heap-size-setting-heap-size-jvm-heap.html – RoflcoptrException

उत्तर

0

शायद आपका मीडिया संसाधन ध्वनिपूल के साथ खेलने के लिए बहुत बड़ा है। साउंडपूल केवल छोटे ध्वनि प्रभाव बजाता है। साउंडपूल एपीआई पर ध्वनिपूल के साथ खेलने के लिए अधिकतम संसाधन के बारे में कोई विनिर्देश नहीं है, लेकिन यदि आप इसका उपयोग करते हैं, तो उदाहरण के लिए, शूटर गेम में एक छोटा विस्फोट जैसे छोटे ध्वनि प्रभाव खेलते हैं। यदि यह आपकी समस्या है, तो आपको अपनी आवाजों को चलाने के लिए मीडियाप्लेयर का उपयोग करना चाहिए।

10

ध्वनिपूल सभी लोड की गई फ़ाइल के लिए बफर आकार को 1 एम के रूप में हार्ड कोड है। इसलिए जब आप SoundPool में बहुत अधिक फ़ाइलों को लोड करते हैं तो आपको शायद 'ढेर आकार ओवरफ़्लो' त्रुटि मिल जाएगी। मेरे पास एक गेम प्रोजेक्ट पर भी यह समस्या है जो गेम ध्वनि एफएक्स को साउंडपूल में लोड करेगी और समाधान निम्नानुसार है:

  1. मीडियाप्लेयर में लंबे/बड़े पृष्ठभूमि संगीत चलाएं।
  2. ढेर त्रुटि को रोकने के लिए बहु साउंडपूल उदाहरणों में छोटी ध्वनि फ़ाइलें चलाएं। बहु SoundPools के लिए नमूना कोड:


/** 
    * Multi SoundPool to prevent memory error. 
    */ 
public class SoundPools {

private static final String TAG = "SoundPools"; private static final int MAX_STREAMS_PER_POOL = 15; private List<SoundPoolContainer> containers; public SoundPools() { containers = Collections.synchronizedList(new ArrayList<SoundPoolContainer>()); } public void loadSound(Context context, String id, String file) { Log.d(TAG, "SouldPools load sound " + file); try { for (SoundPoolContainer container : containers) { if (container.contains(id)) { return; } } for (SoundPoolContainer container : containers) { if (!container.isFull()) { container.load(context, id, file); return; } } SoundPoolContainer container = new SoundPoolContainer(); containers.add(container); container.load(context, id, file); } catch (Exception e) { Log.w(TAG, "Load sound error", e); } } public void playSound(Context context, String id, String file) { Log.d(TAG, "SouldPools play sound " + file); try { for (SoundPoolContainer container : containers) { if (container.contains(id)) { container.play(context, id, file); return; } } for (SoundPoolContainer container : containers) { if (!container.isFull()) { container.play(context, id, file); return; } } SoundPoolContainer container = new SoundPoolContainer(); containers.add(container); container.play(context, id, file); } catch (Exception e) { Log.w(TAG, "Play sound error", e); } } public void onPause() { for (SoundPoolContainer container : containers) { container.onPause(); } } public void onResume() { for (SoundPoolContainer container : containers) { container.onResume(); } } private static class SoundPoolContainer { SoundPool soundPool; Map<String, Integer> soundMap; AtomicInteger size; public SoundPoolContainer() { this.soundPool = new SoundPool(MAX_STREAMS_PER_POOL, android.media.AudioManager.STREAM_MUSIC, 0); this.soundMap = new ConcurrentHashMap<String, Integer>(MAX_STREAMS_PER_POOL); this.size = new AtomicInteger(0); } public void load(Context context, String id, String file) { try { this.size.incrementAndGet(); soundMap.put(id, soundPool.load(context.getAssets().openFd(file), 1)); } catch (Exception e) { this.size.decrementAndGet(); Log.w(TAG, "Load sound error", e); } } public void play(Context context, String id, String file) { android.media.AudioManager audioManager = (android.media.AudioManager) context .getSystemService(Context.AUDIO_SERVICE); final int streamVolume = audioManager.getStreamVolume(android.media.AudioManager.STREAM_MUSIC); Integer soundId = soundMap.get(id); if (soundId == null) { soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { soundPool.play(sampleId, streamVolume, streamVolume, 1, 0, 1f); } }); try { this.size.incrementAndGet(); soundPool.load(context.getAssets().openFd(file), 1); } catch (IOException e) { this.size.decrementAndGet(); Log.w(TAG, "Load/Play sound error", e); } } else { try { soundPool.play(soundId, streamVolume, streamVolume, 1, 0, 1f); } catch (Exception e) { Log.w(TAG, "Play sound error", e); } } } public boolean contains(String id) { return soundMap.containsKey(id); } public boolean isFull() { return this.size.get() >= MAX_STREAMS_PER_POOL; } public void onPause() { try { soundPool.autoPause(); } catch (Exception e) { Log.w(TAG, "Pause SoundPool error", e); } } public void onResume() { try { soundPool.autoResume(); } catch (Exception e) { Log.w(TAG, "Resume SoundPool error", e); } } } }

संबंधित मुद्दे