Android :: Playing Multiple Sounds At Same Time In Application
Apr 13, 2010
I am unable to use the following to code to play multiple sounds/beeps simultaneously. In my onclicklistener I have added
... public void onClick(View v) { mSoundManager.playSound(1);
mSoundManager.playSound(2); } ...
But this plays only one sound at a time, sound with index 1 followed by sound with index 2. How can I play atleast 2 sounds simultaneously using this code whenever there is an onClick() event?
public class SoundManager {
private SoundPool mSoundPool;
private HashMap<Integer, Integer> mSoundPoolMap;
private AudioManager mAudioManager;
private Context mContext;
public SoundManager() {
} public void initSounds(Context theContext) {
mContext = theContext; mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
mSoundPoolMap = new HashMap<Integer, Integer>();
mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
} public void addSound(int Index,int SoundID)
{ mSoundPoolMap.put(1, mSoundPool.load(mContext, SoundID, 1));
} public void playSound(int index) {
int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, 1f);
} public void playLoopedSound(int index) {
int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, -1, 1f);
} }
View 1 Replies
Jun 14, 2010
Shown are a few lines of code. If I play a single sound, it runs fine. Adding a second sound causes it to crash.
private SoundManager mSoundManager;
/** Called when the activity is first created. */
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.sos);
mSoundManager = new SoundManager(); mSoundManager.initSounds(getBaseContext());
mSoundManager.addSound(1,R.raw.dit); mSoundManager.addSound(1,R.raw.dah);
Button SoundButton = (Button)findViewById(R.id.SoundButton);
SoundButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) { mSoundManager.playSound(1);
mSoundManager.playSound(2); } } ); }
View 1 Replies
View Related
May 19, 2010
I'm playing some MediaPlayer instances at the same time (4 or 5) but sometimes when I try to start a new media player it doesn't work and an error is shown on the log:
E/AudioFlinger( 1073): no more track names availlable E/AudioTrack( 1073): AudioFlinger could not create track, status: -12 E/AudioSink( 1073): Unable to create audio track E/VorbisPlayer( 1073): mAudioSink open failed
It also happens when there're only 3 or 2 MediaPlayer playing at the same time. What does it mean this error? How can I workaround with it? Actually checking the isPlaying() after the start() call does not seem very helpful as every call returns true. I've to say that every MediaPlayer is created once via MediaPlayer.create.
View 5 Replies
View Related
May 1, 2009
I have an application that I developed using the Android 1.1 SDK that I am trying to port to Android 1.5. In my application, I record a sound through the microphone and then do various things with it, including playing it back using a MediaPlayer object. My code works fine when I use the 1.1 target, but when I use a 1.5 target I get this error when setting up the player:
Command PLAYER_SET_DATA_SOURCE completed with an error or info PVMFErrNotSupported error (1, -4) Couldn't setup MediaPlayer java.io.IOException: Prepare failed.: status=0x1 at android.media.MediaPlayer.prepare(Native Method) at org.byu.chum.AudioUtils.AudioRecording.stopRecording (AudioRecording.java:92) at org.byu.chum.SoundRecorder.Recorder$StopListener.onClick (Recorder.java:198)...
It seems like Android isn't liking the format of my media, but I don't know why, since I just recorded that very format on the Android device. Here's the code that is throwing the error:
player = new MediaPlayer();
try { player.setDataSource(recordFile.toString());
player.prepare(); } catch (IOException e) { Log.e("playRecording", "Couldn't setup MediaPlayer", e); }
View 13 Replies
View Related
Feb 5, 2009
I am using mp3 sound in my game (used wav format also) while playing sound I get problem as "obtainBuffer timeout (is the CPU pegged)" and then sound gets played after some time i.e it is not synchronized with the game play.
View 10 Replies
View Related
Aug 29, 2010
How can I make progress bar to measure time (pause/playing/total time) of different video which is streaming from website?
View 2 Replies
View Related
Nov 9, 2010
I have 5 mp3 files stored on the assets folder. The files are all 25 KB. I load the files using:
manager = context.getAssets();
this.inputStream = manager.openFd(fileName).createInputStream();
Whenever I try to play the files, the sounds are all messed up like they were mixed or something.
I've zip aligned the app already but with no results.
View 3 Replies
View Related
Feb 16, 2009
I am working on the Eclipse Emulator and with SDK 1.0 Release 2. What I would like to do is to play a simple C note with with code. Does android provide the necessary interface to produce such note sounds? Is there a sound library and API I can readily use on the device (and emulator)?
View 3 Replies
View Related
Jul 28, 2010
I have some pretty simple Soundboard applications on the Android Market that work flawless on an LG Ally, the Motorola Droid, and the Nexus One, but I recently received an e-mail from a user with the Motorola DroidX claiming that most of the sounds do not work. I've exchanged a few e-mails with him. He claims the Soundboard is the only application running, and he's double checked to make sure that the Media Volume wasn't set to minimum. I really don't have access to one either to play around with. The application isn't doing anything cosmic to play the sounds. Below is a code snippet. Any insights into what might be causing the hang up are greatly appreciated.
public void play(Sample sample) {
Log.v(TAG, "Playing: " + getString(sample.getButtonTextResId()) + " (" + sample.getSoundResId() + ")");
if (mPlayer != null) { mPlayer.stop(); mPlayer.release();
} MediaPlayer player = MediaPlayer.create(this, sample.getSoundResId());
mPlayer = player; if (player != null) { player.setVolume(1.0f, 1.0f);
player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override public void onCompletion(MediaPlayer mp) { mp.release();
mPlayer = null; } } ); player.start(); } }
View 1 Replies
View Related
Jun 4, 2010
So I plugged some headphones in so I could try ringtones. It plays out the speaker and the headphones. Is that right? going to try some music next.
View 1 Replies
View Related
Oct 15, 2010
I just noticed a very unpleasant thing about the wildfire - while listening to music (or when playing any other sound), I can hear subtle hissing in the background. It is almost unnoticeable when I'm outdoors and there's noise outside, but it prevents me from listening more quiet music like jazz at home.
Can anything be done about it? Do you people also hear that (you have to be in complete silence and use decent headphones - the hissing is easy to notice as it disappears after 2 or 3 seconds after you pause music). I was so happy about my wildfire - I have 16gb sdcard so I thought it would make a great mp3 player.
View 2 Replies
View Related
Oct 1, 2010
I think I should know this, but my mind has gone blank. I'm making an app that has a few hundred small sound files and I want it to play a certain file dependent on a String I pass to the function. Where I hit the brick wall is getting the resId of the sound file.
View 1 Replies
View Related
May 5, 2010
Is it possible to set different notification sounds for different contacts? By this, specifically, can the Incredible be set to play one ringtone for my husband's texts and a different ringtone for my sister's texts? And if so, how?
View 9 Replies
View Related
Mar 16, 2010
Im trying to find out if you can have multiple notification sounds on the droid. One notification sound for a text message, another for gmail, another for SSM, ect. I got missed call but it doesnt have gmail notifications to change.
View 3 Replies
View Related
Nov 14, 2009
Suppose I want to start a song in Activity A see to it that it plays in Activity B when I move from Activity A to B Now after moving from Activity B to Activity C I want to stop that song and play another song.Please I need Help on this cant figure it out some how
View 2 Replies
View Related
Mar 16, 2010
I am trying to play audio buffered sound (.wav) using AudioTrack. Please see the code below. I need to call this function under a Thread to support simultaneous play. It is fine being under a Thread. It is working fine playing the sound normally. But if i execute playing the sound using AudioTrack one after another continuously (i.e. executing second play before completing the first play sound), produces device crash (force close unexpectedly error). Does anyone come across such problems and resolve it in a way?
View 1 Replies
View Related
Aug 25, 2009
at the moment I am thinking about a new app and need some information to decide whether to develop on Android or an alternative OS. I am particularly interested in "time to first screen", "boot-up time", "time to first Audio" and "app-start" (can be any from the android market or even one of the pre-installed ones) time? Does anyone know a source or perhaps measured those numbers?
View 9 Replies
View Related
Jul 17, 2010
Anyone else have this problem? Everytime I call anyone they say I sound like a robot and they can barely understand me, its definitely the phone and wondering if this is a common issue or I just need to go replace my phone. Also being inside the 14 day return, can i just go in there and get another phone from tmobile or do i have to send it off?
View 20 Replies
View Related
Dec 28, 2009
I was wondering if anyone has come across a stop watch app that would let you set multiple time / countdowns. For example 60 seconds then 15 seconds then back to 60 seconds etc. This would be very useful for working out.
View 1 Replies
View Related
Apr 15, 2010
If anyone knows any good applications that can show multiple time zones in once glance. I'd like to know the current time for where I am as well as the time in my future destinations plus the current time back home.
View 6 Replies
View Related
Nov 1, 2010
I'm trying to run two AsyncTasks at the same time. (Platform is Android 1.5, HTC Hero.) However, only the first gets executed.
Here's a simple snippet to describe my problem:
CODE:................
The output I expect is:
onCreate() is done.
bar bar bar
foo foo foo
bar bar bar
foo foo foo
And so on. However, what I get is:
onCreate() is done.
bar bar bar
bar bar bar
bar bar bar
The second AsyncTask never gets executed. If I change the order of the execute() statements, only the foo task will produce output.
Am I missing something obvious here and/or doing something stupid? Is it not possible to run two AsyncTasks at the same time?
I realized the phone in question runs Android 1.5, I updated the problem descr. accordingly. I don't have this problem with an HTC Hero running Android 2.1.
View 1 Replies
View Related
Jul 30, 2010
I had a basic question. Can my class extend 2 or more classes at a time. What is the syntax. I want to extend Activity as well as Application. Wont this create problems in the manifest file? Activity because, I need to do a couple of things during the onCreate() [binding a service]and Application, because I am creating objects of another class [service class]which needs to be accessible throughout my application.
View 8 Replies
View Related
Dec 14, 2012
I'm new to Android and have the Nexus 4. I have a question about a music timer. I'm playing/streaming my music through Google Play Music. Is there a way to make it stop playing after a set amount of time, say 1 hour? I can't find a way to make it do that. I bought automate it pro but setting up the rules didn't quite work like I thought.
View 1 Replies
View Related
Sep 14, 2010
How to show two dialog at the same time? i don't to use Multiple Select at one dialog.
View 2 Replies
View Related
Apr 5, 2010
I want to have multiple listviews in single activity. But only one listview should be displayed at one time. The listviews will be loaded dynamically. So, how can I fill all the four listviews at the same time and display only one.
If anyone knows the solution then please share it over here. I hope to get a quick response.
View 1 Replies
View Related
Aug 5, 2010
I am currently having some problems controlling the audio on my phone via bluetooth in my car.
When I press the button for the next track on Pandora, that would automatically activate the Android Music Player and play whatever I have stored on the SD card. Ultimately, what I have is 2 sources of music playing at the same time.
Only way to fix it is to get rid of the SD card. OR I can switch tracks using the phone itself.
I realize that this problem isn't limited to the Droid X. I've read about this happening on the Incredible as well.
Anyone know whether a patch (or Froyo can fix this)?
View 6 Replies
View Related
May 2, 2010
I like to listen to live fire dept dispatch, and then be able to go to Google Maps, while the audio is still going, to look up addresses. Is there a way to do this? As soon as I leave the dispatch/web screen, the audio stops. How do I do this? I know there's got to be a way to have multiple apps going at the same time right.
View 1 Replies
View Related
Oct 1, 2010
I'm currently using double twist, but it doesn't seem to allow you to "play all" by an artist. I need a music player that will allow me to do that. I use the phone as a "best of" since all of my music can not fit on the phone.
View 1 Replies
View Related
Oct 24, 2010
I was wondering if there is a way to select multiple emails to delete at one time, rather than one at a time...(using stock mail app)
View 5 Replies
View Related
Jan 30, 2010
My question is how do I sms multiple contacts at same time?
View 6 Replies
View Related