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

Android | Google Sign | Get IdToken correctly in silent
Integrate firebase notifications topics and firebase authentication
Nesting a ScrollView inside a TableRow
AndroidStudio order mixed up when using Intents to open Activities
Prevent Joda-Time to print negative numbers
Getting email from Facebook - FB android SDK
Pick an image and save it in custom folder
Android Insistent Notification Interrupted By SMS - How to make uninterruptable?
Android: Send notifications to all users
Android: Hiding soft keyboard when touching out of EditText
Appcompact EditText give Error on click of Cursor
No design library issue
coronasdk sqlite copy database to computer from device
Upload video to google drive using android api
Android ObjectAnimator+ValueAnimator laggy
Listview doesn't appear at Fragment after second compile

Categories

HOME
google-cloud-platform
wakanda
datastore
powerpoint
pascal
obfuscation
gradient
spring-data-mongodb
zip
jetty
fosrestbundle
fabric.io
32bit-64bit
java.util.logging
automatic-ref-counting
onedrive-api
eip
android-intent
heat
do-while
linear-algebra
package.json
microsoft-dynamics-nav
dimensional-modeling
html5-appcache
foreign-keys
sencha-touch
solrcloud
drive
dpdk
pagespeed
named-entity-recognition
angular-routing
exploit
jquery-callback
roundup
ckfinder
syntax-highlighting
pylons
shared
entity-relationship-model
8051
database-comparison
turfjs
spring-security4
hunspell
hibernate-search
indy10
reverse
getlasterror
python-pptx
reactivekit
opensmpp
ogc
stringtokenizer
odoo-website
plr
dtsearch
reindex
tinkerpop
static-cast
java-bytecode-asm
choice
usart
actor-platform
qtplugin
lrs
greatest-n-per-group
neon
model-associations
hclust
angular-ui-typeahead
project-organization
lz77
html-to-pdf
database-relations
cycle2
tfs-workitem
jdi
ember-cli-rails
lasso
viola-jones
android-broadcast
fits
actionfilterattribute
cocos3d
reflector
live555
jeromq
dtmf
printdialog
mongohq
traceability
http-status-code-410
uimanageddocument
correlated-subquery
matlab-load
twitterizer
svk
squishit
ajax-polling
scrollbars
mathematical-typesetting

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App