• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps MediaPlayer cuting off in Froyo?

Criminosis

Lurker
Jul 14, 2010
3
0
I'm experiencing this when using MediaPlayer on a 2.2 device (my MotoDroid) and using a 2.2 emulator. I'm making a simple sound board as my first app into Android thinking it would press me into learning a gradual curve of basic processes. And so far it has. Though recently I thought I was using bad sound files, but it appears that my app running in 2.2 causes the ending bit of the sound file to be tapered off. The sound files are at most 1 or 2 seconds long.

Code:
mp = MediaPlayer.create(this, audioToPlay);
		makeToast(mp);
		mp.start();

To compare I ran a 2.1 and a 2.2. emulation and installed my app. The 2.1 played the audio files fine, but the 2.2 continued to taper off the endings. I came across another site mentioning duration errors but it was for a different context of us of MediaPlayer. So I created a Toast to show me the duration after clicking.

Code:
double length = mp.getDuration();
		length = length / 1000;
		String audioLength = new String();
		audioLength = "Audio file is: " + length + "long";
		new Toast(this);
		Toast toast = Toast.makeText(this, audioLength, Toast.LENGTH_SHORT);
		toast.show();

Interestingly when playing the same file, here are the outputs :

2.2 : Audio file is 1.635long
2.1 : Audio file is 1.388long

To confirm one of the numbers I ran the app in a 1.6 emulator. Like 2.1 it did not cut off the audio playback.

1.6 : Audio file is 1.388long

So it appears there is a change that affects 2.2 specifically causing it to not playback properly at least for audio files of this tiny length. Any thoughts or workarounds?
 
I recently discovered that I had this problem in one of my apps as well. Thanks for the information about it cutting off at the end. At first I thought it was just sounding weird and wasn't quite sure what was happening.

My solution (not the most elegant, but seems to get the job done)
1. Open up the file with audacity (freeware program) and add about .15 seconds of silence to the end of the file.
2. If for some reason you need the sound to repeat quickly, add some logic that can tell if the media player is still playing and pause it.
3. If you aren't familiar with audacity, when you export an mp3, it likes to add a little bit of silence to the beginning of the file (not sure why). Therefore, I use the media player to "seek ahead" slightly.

Listed below is part of the code I am using.

Code:
            if(player.isPlaying())
                player.pause();
            
            player.seekTo(50);
            player.start();
 
Upvote 0
I tried out your solution, but my audio files were so short they needed more than 0.15 extra seconds. My experience was that files below the cutoff (somewhere between 0.275 and 0.28 seconds) play for what seems like the right amount of time, but without producing any sound, while longer files seem to play fine (although there could easily be problems I'm not hearing, since those files are silence after the first 0.05 seconds)
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones