Error when playing Media Files - android

I'm using MediaPlayer to play some sounds files, which at times overlap. I notice that in the LogCat window I keep getting this message:
android max instances of component OMX.TI.ACC. Decode already created.
It seems to have no effect on my application as the sounds continue to play just fine. Does anyone know what this message means, and do I need to worry about it?

SoundPool may be a better option for playing multiple, short sounds.
Creating SoundPool
public static final int SOUND_1 = 1;
public static final int SOUND_2 = 2;
SoundPool mSoundPool;
HashMap<Integer, Integer> mHashMap;
#Override
public void onCreate(Bundle savedInstanceState){
mSoundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 100);
mSoundMap = new HashMap<Integer, Integer>();
if(mSoundPool != null){
mSoundMap.put(SOUND_1, mSoundPool.load(this, R.raw.sound1, 1));
mSoundMap.put(SOUND_2, mSoundPool.load(this, R.raw.sound2, 1));
}
}
Then play a sound by calling a custom function.
Playing Sound
/*
*Call this function from code with the sound you want e.g. playSound(SOUND_1);
*/
public void playSound(int sound) {
AudioManager mgr = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume = streamVolumeCurrent / streamVolumeMax;
if(mSoundPool != null){
mSoundPool.play(mSoundMap.get(sound), volume, volume, 1, 0, 1.0f);
}
}

Related

how can i set mediaPlayer speed for api less then 23

player.setPlaybackParams(player.getPlaybackParams().setSpeed(0.5f));
this requires an api call 23
iam trying to use SoundPool but it is not so efficent as of MediaPlayer Is any alternate to SoundPool for audioPlaying
final float playbackSpeed=1.5f;
final SoundPool soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
final String path=Environment.getExternalStorageDirectory().getAbsolutePath() + "/folioreader/audio"+".mp3";
final int soundId = soundPool.load(path, 1);
AudioManager mgr = (AudioManager) mHalfSpeed.getContext().getSystemService(Context.AUDIO_SERVICE);
final float volume = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener()
{
#Override
public void onLoadComplete(SoundPool arg0, int arg1, int arg2)
{
soundPool.play(soundId, volume, volume, 1, 0, playbackSpeed);
}
});
soundPool.pause(soundId)
Use media codec class. This class can decode it and you can use Audio Track on decoded data to render (play) it. But you need to skip the samples as per your speed requirement to play in the particular speed. This approach should work. Refer mediacodec and audiotrack in android developer resources.

SoundPool play not working

I'm trying to play a .mp3 sound from my raw folder, but somehow the sound doesn't play. The code does execute the play method but it doesn't produce sound. Here's my code:
public SoundPlayer(Context context) {
this.context = context;
AudioManager audioManager = (AudioManager) context.getSystemService(Service.AUDIO_SERVICE);
soundPool = new SoundPool(3, AudioManager.STREAM_MUSIC, 0);
clickId = soundPool.load(context, R.raw.bubbleclick, -1);
errId = soundPool.load(context, R.raw.bubbleclickerror, 1);
countId = soundPool.load(context, R.raw.countdowntick, 1);
float actualVolume = (float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
float maxVolume = (float) audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
volume = actualVolume / maxVolume;
}
public void playBubbleClick() {
if (!isMuted()) {
soundPool.play(clickId, volume, volume, 1, 0, 1);
}
}
I first instantiate the SoundPlayer class (custom class), and then call playBubbleClick()
I didn't solve the issue but I worked around it by calling the play method in the onLoad event (when setting an onLoadListener). This does solve it, but still shouldn't be the way it is done.

android sound pool not appear

I want to add a sound effect when a user clicks on a button.
I tried this:
case R.id.b_all_addresses_addAddress:
// Getting the user sound settings
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
float actualVolume = (float) audioManager
.getStreamVolume(AudioManager.STREAM_MUSIC);
float maxVolume = (float) audioManager
.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume = actualVolume / maxVolume;
if (loaded)
soundPool.play(soundID, volume, volume, 1, 1, 1f);
else
Toast.makeText(this, "could I hate you God more?", Toast.LENGTH_SHORT).show();
in my on create I did this:
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
#Override
public void onLoadComplete(SoundPool soundPool, int sampleId,
int status) {
loaded = true;
}
});
soundID = soundPool.load(this, R.raw.thip, 1);
the sound is just 6 KB.
My Problem
I can't hear the voice
what values are you getting back for volume?
They should be between 0.1 and 0.99. Try using 0.5 as a hard-coded setting and see whether that works. I vaguely remember someone here once reported a "bug" in SoundPool which meant that 0 and 1 meant "mute" and your volume had to be between these two values in order to be heard.
Also: What format is your sound in? not all phones can play all the formats. Some need ogg, some are fine with WAV.
This here works for me on HTC Sensation XE, Android 4.03:
*WAV
*2 Channels
*16 bit PCM
*44.1kHz

Android play music in a random amount of time

Now I can play a music in android. But I want to play this sound in a random amount of time between 2 to 8 seconds.How Can I randomly play it that for example the first time, it plays for 2 seconds, the next time 7 sec and so on? Can anybody help me?
Go through these links:
Random number Generation
Media Player
Timer
you will get an idea.
Sound in android is played like this :
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
int mSoundID = mSoundPool.load(this, R.raw.sound1, 1);
float lActualVolume = (float) audioManager
.getStreamVolume(AudioManager.STREAM_MUSIC);
float lMaxVolume = (float) audioManager
.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float lVolume = lActualVolume / lMaxVolume;
// Is the sound loaded already?
if (mSoundIsLoaded) {
mSoundPool.play(mSoundID, lVolume, lVolume, 1, 0, 1f);
I think you have been given plenty of help to figure the random number part out.
You will have to put the sound file in your assets/raw directory.
edit:
I forgot to mention where the mSoundIsLoaded parameter came from.
I set it when my sound has been loaded. I do this in my onCreate method. when the sound is loaded I set the boolean field called mSoundIsLoaded. I do this to prevent NullPointerExceptions when playing the sound
the loading of the sound looks like this:
mSoundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
#Override
public void onLoadComplete(SoundPool soundPool, int sampleId,
int status) {
mSoundIsLoaded = true;
}
});
mSoundID = mSoundPool.load(this, R.raw.sound1, 1);

Issue with Soundpool and Samsung Galaxy S

I recently acquired a Samsung Galaxy S, Android 2.1 update and after running my app I found that some of the sound effects play twice concurrently. This is odd because the sound effects which exhibit this behaviour seem random - on some instances some will play twice on others they will play once as expected. This bug has not been reported on any other hardware platform for my app. I have only seen one reported incident of this on this site and the person switched to use MediaPlayer however I really want to get a remedy for this.
When the app is run it initiates the Soundpool as follows,
public static final int SOUND_EXPLOSION = 1;
public static final int SOUND_CLEAR = 2;
public static final int SOUND_CLICK = 3;
public static final int SOUND_MAGIC = 4;
public static final int SOUND_ROCKET = 5;
public static final int SOUND_MELT = 6;
private SoundPool soundPool;
private AudioManager mgr;
private HashMap<Integer, Integer> soundPoolMap;
private void initSounds()
{
soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
soundPoolMap = new HashMap<Integer, Integer>();
soundPoolMap.put(SOUND_EXPLOSION, soundPool.load(getContext(), R.raw.explosion3, 1));
soundPoolMap.put(SOUND_CLEAR, soundPool.load(getContext(), R.raw.pop, 1));
soundPoolMap.put(SOUND_CLICK, soundPool.load(getContext(), R.raw.click, 1));
soundPoolMap.put(SOUND_MAGIC, soundPool.load(getContext(), R.raw.swoosh, 1));
soundPoolMap.put(SOUND_ROCKET, soundPool.load(getContext(), R.raw.rocket, 1));
soundPoolMap.put(SOUND_MELT, soundPool.load(getContext(), R.raw.melt3, 1));
mgr = (AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE);
}
Sound fx are then played by calling the following sub, (PlaySound is a global toggled by the user options)
public void playSound(int sound)
{
if (PlaySound == true)
{
Log.w("playSound","Playing Sound" + sound);
float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume = streamVolumeCurrent / streamVolumeMax;
soundPool.play(soundPoolMap.get(sound), volume, volume, 1, 0, 1f);
}
}
As you can see there is a log call which I used to see how many times the sub had been called although this revealed that when the bug occurs the routine is only called once when the sound is heard twice from the device.
I have also one last sub which is called when the surface view is destroyed to tidy up.
public void ReleaseSounds()
{
if (soundPool != null)
{
soundPool.release();
soundPool = null;
}
}
Has anyone else had this issue, if so how did you resolve it? Any help on this would be greatly appreciated,
Many thanks in advance
Converting sound files to OGG in the raw folder seems to have resolved this bug - I have not seen a repeat of it since.

Categories

Resources