android


AudioCache Heap size overflow issue req size: 1053184, max size: 1048576


I am developing an app where i want to play two mp3 files simultaneously one as background music and want to control the sound of each player separately. The file size is 5 mb each
i have done with main audio file but when i try to play second file with it it throws error
SoundManager mSoundManager = new SoundManager();
mSoundManager.initSounds(getBaseContext());
mSoundManager.addSound(1,R.raw.music);
mSoundManager.addSound(2,R.raw.mentalafslapning);
mSoundManager.playSound(1);
mSoundManager.playSound(2);
}
class SoundManager
{
private SoundPool mSoundPool;
private HashMap<Integer, Integer> mSoundPoolMap;
private AudioManager mAudioManager;
private Context mContext;
private Vector<Integer> mAvailibleSounds = new Vector<Integer>();
private Vector<Integer> mKillSoundQueue = new Vector<Integer>();
private Handler mHandler = new Handler();
public SoundManager(){}
public void initSounds(Context theContext) {
mContext = theContext;
mSoundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
mSoundPoolMap = new HashMap<Integer, Integer>();
mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
}
public void addSound(int Index, int SoundID)
{
mAvailibleSounds.add(Index);
mSoundPoolMap.put(Index, mSoundPool.load(mContext, SoundID, 1));
}
public void playSound(int index) {
// dont have a sound for this obj, return.
if(mAvailibleSounds.contains(index)){
int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
int soundId = mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, 1f);
mKillSoundQueue.add(soundId);
// schedule the current sound to stop after set milliseconds
mHandler.postDelayed(new Runnable() {
public void run() {
if(!mKillSoundQueue.isEmpty()){
mSoundPool.stop(mKillSoundQueue.firstElement());
}
}
}, 3000);
}
}
IS it possible to play both the files at same time and control the volume of each separately?
All the comments I have read suggest that SoundPool is not applicable to playing long sounds.
You have to get a bit suspicious of OS quality when every one gets an error message with the exact same parameters, else it is an amazing coincidence.

Related Links

Firebase Databaseui give Blank Result in Android
Ionic2 : Add platform doesn't work
2 dependent retrofit requests made by RxJava
SharedPreference to checking Actionbar status
Delphi/android how to find the involved line of code by it's address
AdMob ads not displaying in Xamarin Android application
Error in opening actvity from fragment through ListView using switch case
Using FabricJS With React-Native
How can I add android StateListAnimator in style.xml file?
how to invoke listview setAdapter automatically after add new item
Relative Layouts Background resize on keyboard open
Android - Square ImageButton in GridLayout
Android: Unable to Get All SysEx Messages from MIDI File
kapt Build Fails With Dagger Android Processor
Can i register MVP Presenter inside Fragment
How to read temperature from ti SensorTag Android

Categories

HOME
windows
phantom-dsl
gridview
cobalt
gdb
string
ecmascript-6
alexa-skills-kit
pda
battery
apiblueprint
gradient
replace
entity-framework-core
rom
missing-data
nfs
title
okhttp
pattern-matching
ibeacon-android
redis-sentinel
jxl
openbugs
shared-libraries
3nf
standards
video-editing
oledb
selinux
articulate-storyline
pchart
monit
direct3d11
delimiter
apktool
scatter3d
postback
jmockit
spring-security4
mnist
openproject
playframework-2.1
watchman
reactivekit
health-monitoring
resolution
claims
apache-directory
facebook-social-plugins
fwrite
xbmc
twilio-click-to-call
filehandle
avx
skin
d3-force-directed
rmongo
cvxpy
vcloud-director-rest-api
node-request
omniauth-facebook
data-protection
libav
design-principles
linklabel
opl
fiware-monitoring
morton-number
sapscript
canalyzer
finalbuilder
rdflib
mirror
matlab-deployment
openbabel
dbaccess
angular-gettext
browserify-shim
formview
universal-image-loader
tweenlite
insight.database
unix-socket
draw2d-js
spring-remoting
android-framework
decoupling
android-audiorecord
scriptaculous
bin
inputmismatchexception
kogrid
cffile
gpars
kaleidoscope
time.h
facebook-timeline
wp7test
pdfviewer
zope.interface
fusefabric
box2d-iphone
google-maps-mobile
promotion-code
update-statement
burndowncharts
skype4java
tui
fail-fast-fail-early
flvplayback
pbcopy
appliance

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App