Soundpool or media player? - android

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

Related

Android : How to play multiple mp3 tracks simultaneously

In the application, songs will have been split into multiple tracks, one track per instrument.
I need to be able to play all the tracks simultaneously.
I have seen that MediaPlayer is not able to do this, indeed having 5 to 10 separate tracks would cause too much latency.
SoundPool states that it is specifically for short sounds and so is inappropriate for this.
It would appear that AudioTrack would be the answer, but that requires decoding each mp3 into pcm data before playing it.
So, here are my questions -
Even though I have not found any, do any tutorials exist demonstrating how to achieve this ?
Can anyone advise on how to play multiple audiotracks simultaneously ?
Are there any existing examples on how to decode mp3 files using the NDK ?

Play audio in background without interrupting mediaplayer

How can I play background audio, in Android, without interrupting the MediaPlayer playback, by either using MediaPlayer (preferred) or OpenSL ES?
I know SoundPool is able to play sound effects without interrupting any MediaPlayer playback, but the size is limited to 1M per effect, which is way to less. Not requesting audio focus, via AudioManager doesn't seem to work either, audio doesn't play at all in this case.
And in the case of OpenSL ES, all audio generally stops when I start to play a longer asset file. It's similar to the behaviour of SoundPool described above.
Edit from the comments:
I don't want to interrupt other music players, it's the background
audio of a game, which shall play without interrupting the, for
example, music of a player. Games like Subway Surfer, Clash Royale and
such seem to have this achieved somehow, but I could not achieve it
via OpenSL ES, or MediaPlayer.
In order to play sound in background you can use SoundPool, AudioTracks and OpenSlES.
Soundpool: Use small files and make a sequence. In my last project i use 148 sound files (all small) in different scenarios and played using soundpool. Make a list and play one by one or in parallel. Also in games usually you have a small set of sound for particular scenario and it loops. Best is soundpool for that. You can also perform some effects like rate change. Also ogg files are way small, so use them.
AudioTrack: You can use RAW PCM data in audio track. If you want you can extract pcm data using MediaExtractor from almost all formats and use it. But it will be a little work for you in your case, but it is really good (supports huge data, even live streaming).
OpenSLES: Apparently android uses opensles in background for all its purpose. So using it will help you a lot. But it's not easy to get everything done on it. You need to learn more for lesser work.
I have been deeply working on OpenSlES for about 20 days and still i will say for small purpose use soundpool, medium to high level implementation use AudioTracks and for kickass implementation use OpenSLES.
PS: It will be bad effect on your user if you play game sound in background while they are playing their music or their call. Personal experience.

Short audio files

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?

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.

Android: Switching noise in SoundBoard

I am developing a Soundboard application. I use MediaPlayer to Play Ogg sound files. Now when I switch from one sound to another sound, I get a noise similar to the ones heard while switching radio stations. I do not want this noise. How to eliminate it? Any Ideas? Thank You
Probably a silly answer but try adjusting the volume level to the lowest possible before making the switch, then resetting back to the user's original level when completed - sorry.
I found out. It was because of the conversion of the files from mp3 to ogg. MP3 files were of higher bitrate and when converted to ogg ended up in the loss of quality which resulted in the noise.

Categories

Resources