Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old July 14th, 2010, 01:35 AM   #1 (permalink)
New Member
 
Join Date: Jul 2010
Posts: 3
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default MediaPlayer cuting off in Froyo?

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?

Criminosis is offline  
Reply With Quote
Sponsors
Old August 24th, 2010, 11:05 PM   #2 (permalink)
New Member
 
Join Date: Aug 2010
Posts: 3
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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();
DominicDroid is offline  
Reply With Quote
Old September 4th, 2010, 01:07 AM   #3 (permalink)
New Member
 
Join Date: Jul 2010
Posts: 3
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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)
alex42 is offline  
Reply With Quote
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mediaplayer and NAS ptrzet Android Media 0 December 2nd, 2010 06:59 AM
MediaPlayer and streamreader Antti Application Development 0 July 14th, 2010 05:55 AM
.wav and mp3 as ringtones --interaction with mediaplayer hinesw Android Media 1 April 1st, 2010 11:47 AM
Unexplained error from MediaPlayer Sir^Knigget Application Development 1 February 22nd, 2010 08:05 PM
Audio Analysis with MediaPlayer onionparadise Android Media 0 June 4th, 2009 11:58 AM



All times are GMT -5. The time now is 11:30 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo