their are some questions on stackoverflow about looping sound in android but neither gave me correct answer so i start new thread,
I want to loop a sound without gaps in android. I tried to use the code mediaplayer.setLooping(true) for mp3,ogg and wav file to loop the sound, but there is always a little pause when the first sound is over and the next sound start..my audio length is 2 min. and file size is more than 1 mb so i cant use soundpool for repeating sound.
i didn't know how to solve this issue.
Ok basically you have to create two objects of media player and then if time of first music is going to b finished then call the other one and your problem is solver
Related
I'd like to create an application that plays a sound repeatedly at a regular interval. I've tried using the in onTick method for the CountdownTimer class and then using a MediaPlayer object to play the sound. This works for moderately slow rates of repeation (1 sound per second) but anything faster than that and the program doesn't work properly. I suspected that the issue was the length of the media file I used, but shortening it didn't seem to do anything. Any suggestions?
I'm trying to loop a ~30 seconds audio track multiple times. I'm using a MediaPlayer to play the sounds, here is the code where its created:
mAnimalMediaPlayer = MediaPlayer.create(mContext, fish.getSound());
I then call:
mAnimalMediaPlayer.setLooping(true);
mAnimalMediaPlayer.start();
when a play button is clicked. When the track loops, there is a small but noticeable pause between the track ending and the new loop beginning. I am positive that the audio file im using does not contain any actual pause.
Here is an android bug report which has been up for some time: https://code.google.com/p/android/issues/detail?id=18756
I've tried a few workarounds (such as using .ogg files instead of .mp3) but the problem persists.
I'm looking for any possible workaround that will allow me to seamlessly loop the playback multiple times.
There is a very noticeable pause. However, I have just discovered through experimentation on an emulator running level 25 that if one prepares two identical players and alternately starts them one after the other when the other has finished then the gap becomes much more difficult to hear.
I have two media files located locally - mp4 video and m4a audio, which have to be played in sync. I use MediaPlayer objects for this purpose, all start/pause methods are called simultaneously.
Sometimes I see the difference between audio and video right after players start, sometimes after tapping on pause/resume.
I added logs, and see that after pausing media players, their position differs (e.g. MediaPlayer with audio file: 1820ms, MediaPlayer with video file: 1760ms).
One more interesting thing is that seekTo operation with audio file works good, while with video it's really unpredictable.
Please suggest what is the reason of such a behavior and which solutions are available in order to fix that?
I think that this effect with the video timing depends on how the " key frames", which contain a full frame of information have been encoded. It's only possible to locate to one of these keyframes.
Video editing software gets over this by rolling the deltas from intervening i-frames to the exact seek position.
I am currently trying to make a Soundboard application for my Android.
Using Eclipse, I have successfully made buttons and coded them so that when pressed, they play .ogg sounds in the res/raw folder. All is okay.
Now, I have discovered that any files over about 6 seconds long aren't playing fully.
Is there any way to correct this problem? I would normally just trim the files, but some of them need to be a bit longer, but none are over 50 seconds.
Thanks alot!
What is happening is the mediaPlayer.start() instruction is being called before the file has finished fully loading. Assuming you are using mediaPlayer.create(this, resid) followed by .start() there are a few things that can help. The "right" way to do it is to put the .start() instruction inside of an onPreparedListener since .create calls .onPrepared the first time, but honestly when I put that in my soundboards I got tons of crash reports, so I reverted to just using .start after .create.
I found the problem usually occurs if the sound file is very high bitrate, or if the app is installed on a slow sdcard. I use mp3's, but usually cap the bitrate at 96k and put in the app description that if the clips aren't playing fully to move the app back to internal memory and the complaints seem to have stopped.
I have been attempting to play a bunch of sounds in my app as some views switch. The sound is narrative for the views and is between 3 and 10 seconds each, of which there are about 30.
First, I tried loading them all into a sound pool and passing it to a hashmap on program load, then I simply play them when required. This worked for the first 5 or 6 sounds but once I started to add more sounds to the sound pool, the later ones did not play. I assume this is due to the 1MB limit I have read about on soundpool.
I tried switching to just loading the sound and passing it straight to play on the next line however, no sounds play. Logcat just shows a reset and command cancelled for the player.
I switched then to loading the file and pointing to it with the hash map, however, even after doing an unload and loadimg a new sound at the same index it would just play the same sound every time.
I have tried MediaPlayer but it is ineffective for my desired application.
Can anyone suggest a way I should look to implement this properly? And should I be trying to load all sounds before hand or not?
I think you need to wait for the load to complete before you can play it. Add an onLoadCompleteListener and then play it when that is invoked.