Short audio files - android

I'm trying to play a couple of short audio files (ca. 2sec) in an Android App with the Media Player. They do play, but for some of them I get a click sound at the end (which differs from file to file).
There are no click-sounds when I play it on the PC, also I tried to convert it from .mp3 in .ogg and modified the soundfiles themselves, nothing helps, I think the problem is probably the Media PLayer.

For short audio files, like sound effects, I would use a SoundPool
Also see this question and answer here: The correct way to play short sounds Android?

Related

Alternative to MediaPlayer to play an audio file

Is there an alternative way of playing audio data other than using MediaPlayer. The audio comes from a resource and not a file. I also want it played from a service and not from an activity or using a built-in music player app. What alternative APIs exist? I am coming to the conclusion after much testing that MediaPlayer in Android 4.1 is buggy and fails much more than under previous versions, so I am looking for an alternative means of playing audio.
I think the AudioTrack is the best thing to use here. as you are looking to play from resource then you can use raw pcm audio data as resource.

Play mutiple audio at a time

I need to play multiple audio track at a time from sd card. I was trying to play with SoundPool. But it does not support larger files.
I tried with AudioTrack but it needs pure PCM code. PCM code generation bit of complex from mp3 or 3gp file, as android do not have anything build in to that.
I've look OpenSL Engine, But did not find any good example or tutorial to work with it.
How can I play multiple audio at a time in loopy style? any idea, suggestion would be great a help.

Streaming audio file and caching it

I want to stream an audio mp3 file and then play it through android media player plus I also want to cache this file, so that mediaplayer don't have to stream for recently played tracks.
I have tried using prepareAsync method but it doesn't give me access to buffer content, so I have decided to stream the audio file myself and then pass it to the media player for playing. I have achieved this by following this article here but this approach has a problem i.e. while transferring the file to media player it goes into error mode which causes my player to behave inconsistently.
When media player enters its error mode it doesn't come out of it automatically so I am forced to create a new media player and then re-provide it the downloaded file, this workaround causes the user to experience an undesired pause in the song playing.
So, does any one have improved an version of code given in above link? or do they know a better solution to this problem or is there is actually a library for streaming an audio file in android?
Thanks
The link you provided looks like a less than ideal solution (not to mention outdated). What you probably want is a local proxy server that gives you access to byte data before the MediaPlayer gets it. See my answer here for a little more explanation.

Soundpool or media player?

I am doing a cards game for android and I want that everytime a card is thrown, to play throwing sound. It is the same file. I will have also other sounds playing like background music , and certain clicks.
What do you recommend to use, sound pool or create MediaPlayback and play it? What would be the advantage/disdvantage to each one? should I use ogg or mp3/wave file?
Any help in this is appreciated.
Thank you
I would use the sound pool for short clips. I might be wrong but the sound pool has a smaller overhead plus it's the correct way to play short clips, it also allows you to specify how many times per second said sound clip can play which helps slower phones.
With regards to the mp3 vs ogg I use mp3. I don't believe there is any performance issues. Ogg is licence free but that doesn't really matter with regards to your app. Plus it might help if you plan on using these clips on another platform that doesn't play ogg files. No names mentioned :P

Playing a WMA in my android app

Simple question:
I'm using MediaPlayer to play mp3 files (they play just fine), but also i need support for WMA files. I know some devices support it, but not all of them, but i want some way where I'm sure it will play in any device. Is there anything i can implement or do so i can play Mp3 and WMA files?
right now i got two test buttons, with the same code, one the source is an Mp3 (works) the other same code with a wma (fails)
MediaPlayer mp = MediaPlayer.create(this, Uri.fromFile(source));
mp.start(); // no need to call prepare(); create() does that for you
Thanks.
Alex
Why don't you reencode the wma file to mp3 or ogg (preferentially)? wma is a closed format and it's support depend on some libraries not always available on Android devices, and they're not part of the AOSP tree itself. That being said, most AOSP derived ROMs wont play wma's.
So the best thing to do is to reencode the files to ogg or mp3.

Categories

Resources