So I have an app where mp3 file is being played using the MediaPlayer. On most devices everything is fine but on Samsung and some other (like HTC One S) devices the same mp3 plays "too fast" (skipping gaps): looks like player does not handle sound gaps (silence) correctly. These mp3s are just speech and speech naturally has gaps (silence) between spoken words. And these gaps are not played correctly in terms of time - MediaPlayer just skips them. As result mp3 is played faster by the duration of all gaps it contains.
What could be a reason and solution for this?UPDATEI'd found that its about frequency+VBR. Somehow if mp3 is of 22050/24000/32000 Hz instead of 44100 or 48000 and VBR or ABR is used the issue raises up. Im using LAME for mp3 encoding. If I remove "--resample 22.05" option so the resulting mp3 becomes 44.1kHz there is no issue playing this mp3 on samsung phone. However the resulting size of mp3 becomes twice bigger which is not acceptable for me cuz in this case my apk becomes bigger than 50Mb. So now the question is how to properly compress mp3 as 22kHz/VBR/MONO.
The issue was fixed in the following way: I added a white noise to an original sound and then encoded it to MP3 format. Resulting files became bigger in size but also they become more compatible (with Samsung devices) The original audio file (made at recording studio) is too clean meaning that silence/pauses in speech (between pronounced words) has no waveform if look in sound editor, its like an ideal silence. So on variuos Samsung devices such MP3-encoded files played with described issue. However on most other devices and PCs such MP3 files played just fine. Once again - Samsung "rules"!
You need to Google our for controlling playback speed in your application I mean to say that there must be some sort of 'playback rate' variable which must be a floating point value something between 0 to 1. This might help you in some workarounds for your app hope you find this somewhat helpful in anyway . O by the way here are some useful links that might help you out as well and if not then we have to keep waiting in the waiting queue for Samsung ;-) if its specifically related to them happy coding
http://code.google.com/p/android/issues/detail?id=1961
play an mp3 with MediaPlayer class on Android issues
Regards
Anas.
Related
I am creating a video using an Android app and after this mp4 Video File is created it does not play back properly. The audio will play over a still frame from the video and then once the timer reaches the end then the video will play several moving frames.
This issue is only occurring when I create the video on a Samsung Galaxy S7 and not on any other phones.
I am not experienced in video file encoding so I do not even know where to start with debugging what is wrong with the file. If someone could explain what causes something like this That would be amazing
The first video sample decode time in your file is 1506981408/90000 - which is giant - about 4.5 hours into the stream.
So the entry is obviously bogus.
Hard to say where is bogus decode time is coming from - may uninitialized memory of some sort.
See 'stts' box offset 1052223 - first array entry.
I corrected your video and put a copy here: https://drive.google.com/open?id=0B1K1m-YmE28DMXdFemZKbXg0WFk
I'm playing mp3 file streamed from the network in my application, some mp3 files has weird behavior: mediaPlayer.getCurrentPosition() is larger than mediaPlayer.getDuration() at the end, for about 3 seconds.
The mp3 files are CBR encoded.
What might be the reason of this?
Finally solved the problem by converting the mp3 files, this is the command I'm using:
lame --mp3input -t -m s -b 128 --cbr input.mp3 output.mp3
There is a few reasons you can get this behavior.
First it appears that people had better results using mp3 files at exactly 44100Hz, because apparently the MediaPlayer class is assuming this value and scale the time accordingly, making strange values for files not using this sampling.
You also need to check the mode of your channels, and try using Joint Stereo or forced L/R Stereo. Joint should be the default, but your files might have been previously bad encoded, so it's worth trying. It's interesting to note that Forced L/R Stereo might loose quality for the same bitrate as Joint.
It would also be useful to check the output of soxi which is part of the sox package (you can also do it with ffmpeg), that will give you the number of channels, Sample rate, Bit Rate and Number of Channels.
Also you might want to check the raw content of the mp3 file if you did some treatment on them using any app for the presence of garbage xml content that might have been inserted during the export.
If you have the possibility to modify the mp3 files you're streaming, (which sounds like you do since you can tell the bitrate) these are what I would try first. If it's more like user-upload kind of stuff, maybe you should have a look to another solution instead, like ExoPlayer which has a few thousands stars and active development. It wraps the MediaPlayer api still, but worth a try.
You also have to consider that it might be a threading problem, where the player would stop playing, but the timer would actually keep going, giving you this result where it's superior to the actual duration of the song. 3 seconds seems a bit too much to explain it by that, but that's just a thought.
I have been using media player from last 2 months with normal mp3 files.Few days back my client gave me 16kbps converted low quality files. When I played these files through Media player class.The behaviour which I observed is mentioned below:
(1) mediaPlayer.getDuration() is giving extra duration. For example : If it's 46 sec then duration is returned as 86 sec.
(2) mediaPlayer.seekTo(positionToNavigate) is not working properly and sound position is totally different than original.
I have tried to fix above things many times with different codes but these 2 problems are still there. When I play an MP3 file without conversion like normal quality 128kbps+, the sound and the seekTo work normal.
I want to mention that it is necessary to use low quality MP3 because it has small size and fast downloading from server.
If the issue is encoding/compression, is there other way to compress an MP3 with 16kbps?
I'm using libmpg123 as a library from native code (Android NDK) to decode a MP3 file to PCM (signed 16 bit) data. It works great, with the exception that the speakers make a weird sound once or twice every few seconds. To figure out what was wrong, I opened the audio in audacity and found this weird drop in audio sometimes.
The 'rest' of the audio sounds great, by the way. The overall quality is good.
Any ideas how this might happen? I'm totally lost...
Those are unclipped overflows (a 32768, where 32767 is the largest positive 16bit value). Are you doing anything to the data? Is what you opened the actual mp3 or the decoded pcm (just to be sure)?
I recorded some audio files to use in my app, around 50, so I would like to not record all of them again. I recently used SoundPool to play the audio files on a real device instead of the emulator and you can barely hear them. On the emulator with my PC volume set to max and device to max, I can hear it fine. Should I try to record the files louder or is there another option?
I've found that when targeting mobile devices (and cheap/small laptop speakers for that matter), it is best to do two things to your audio:
Compression: I do not mean data compression, I mean dynamic contrast compression. This will remove some of the level differences between loud and soft parts of the recording, allowing it all to be heard better.
Normalization: When you normalize audio, you take the loudest part of the audio, and scale the entire audio clip up so that the loudest part is at the loudest that can be stored in the audio file.
You can do both of these easily with any audio editing software, such as Audacity.
Finally, you should also keep in mind the reproduceable frequencies on such small speakers.
Most of these speakers are built with speech in mind. Because of this, you will find that they tend to be the loudest in the 700Hz-2.5kHz range.
That is, if your sound effects are low in frequency (think bass), then it will be almost impossible to hear them on a phone's small speaker which cannot reproduce such low frequencies.
If you have more questions on the matter, please visit https://video.stackexchange.com/.
If it is the volume of the recorded files, you can change it using a normalizer like MP3Gain.