The volumes should range from 0 to 1.0, where 1.0 is maximum volume,
i.e. zero attenuation. A value of 10 should be returning an error, but
maybe it's not being passed up properly through the framework.
On Nov 12, 7:57 am, plusminus <[EMAIL PROTECTED]> wrote:
> HI Dave,
>
> I was using (Note: inside runOnUIThread(...)):
> ###############
> final MediaPlayer mp = MediaPlayer.create(MyActivity.this,
> R.raw.some_sound);
> mp.setVolume(10, 10);
> mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
> ###############
> Is it that what you meant?
> Using that I can't hear anything. leaving out the last two lines
> everything is really silent!
>
> The funny thing is that other files, that have the same volume on the
> pc, play with correct volume. :/
> (there I am just using: MediaPlayer.create(MyActivity.this,
> R.raw.some_sound).start(); )
>
> Best Regards,
> Nicolas
>
> On Nov 11, 2:24 pm, Dave <[EMAIL PROTECTED]> wrote:
>
> > By default, the MediaPlayer volume should be set to 1.0, i.e. no
> > attenuation.
>
> > Which stream type are you using when you create the MediaPlayer? Have
> > you checked to make sure that the master stream volume is set
> > correctly?
>
> > On Nov 11, 10:10 am, plusminus <[EMAIL PROTECTED]> wrote:
>
> > > Thx for the code but I have that onCompletion working with the
> > > MediaPlayer already.
> > > The problem actually is that the volume is soooo silent on some files
> > > (even after volume-normalizing them).
>
> > > Does anyone which values to choose, calling the following method on a
> > > MediaPlayer:
> > > ------------------
> > > setVolume(float leftVolume, float rightVolume)
> > > Sets the volume on this player.
> > > ------------------
> > > I was using 10, as that had been returned once from
> > > mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
>
> > >SoundPoolis playing them in the proper loudness. :(
> > > But using an unstable API is not what I'd like to do :(
>
> > > On Nov 11, 9:43 am, Robert Green <[EMAIL PROTECTED]> wrote:
>
> > > > Here's an example for managing sounds that will be played many times
> > > > (like gunshots, explosions, clicks, etc) using a pool and then sounds
> > > > that are just one-offs, like an announcer or an intro sound.
>
> > > > public class MediaPlayerPool {
> > > > private static final String TAG = "MediaPlayerPool";
>
> > > > private Context context;
> > > > private int streamType;
>
> > > > private HashMap<Integer, ArrayList<MediaPlayer>> pools;
>
> > > > public MediaPlayerPool(Context context, int streamType) {
> > > > this.context = context;
> > > > this.streamType = streamType;
> > > > pools = new HashMap<Integer, ArrayList<MediaPlayer>>();
> > > > }
>
> > > > public boolean hasMedia(int resourceId) {
> > > > return pools.keySet().contains(resourceId);
> > > > }
>
> > > > public void addMedia(int resourceId, int poolSize) {
> > > > ArrayList<MediaPlayer> pool = pools.get(resourceId);
> > > > if (pool == null) {
> > > > pool = new ArrayList<MediaPlayer>();
> > > > }
> > > > for (int i = 0; i < poolSize; i++) {
> > > > pool.add(createMediaPlayer(resourceId));
> > > > }
> > > > pools.put(resourceId, pool);
> > > > }
>
> > > > public void playMedia(int resourceId) {
> > > > ArrayList<MediaPlayer> pool = pools.get(resourceId);
> > > > MediaPlayer player = null;
> > > > if (pool.size() > 0) {
> > > > player = pool.remove(0);
> > > > }
> > > > if (player == null) {
> > > > Log.e(TAG, "Pool is empty for resource " +
> > > > resourceId);
> > > > } else {
> > > > player.start();
> > > > }
> > > > }
>
> > > > public void release() {
> > > > for (Integer key : pools.keySet()) {
> > > > ArrayList<MediaPlayer> pool = pools.get(key);
> > > > for (MediaPlayer player : pool) {
> > > > if (player.isPlaying()) {
> > > > player.stop();
> > > > }
> > > > player.release();
> > > > }
> > > > pool.clear();
> > > > }
> > > > pools.clear();
> > > > }
>
> > > > private MediaPlayer createMediaPlayer(final int resourceId) {
> > > > MediaPlayer mp = MediaPlayer.create(context,
> > > > resourceId);
> > > > mp.setOnCompletionListener(new
> > > > MediaPlayer.OnCompletionListener() {
> > > > public void onCompletion(MediaPlayer player) {
> > > > player.seekTo(0);
> > > > returnToPool(resourceId, player);
> > > > }
> > > > });
> > > > mp.setAudioStreamType(streamType);
> > > > return mp;
> > > > }
>
> > > > private void returnToPool(int resourceId, MediaPlayer player) {
> > > > ArrayList<MediaPlayer> pool = pools.get(new
> > > > Integer(resourceId));
> > > > pool.add(player);
> > > > }
>
> > > > }
>
> > > > public class MediaPlayerSoundManager {
> > > > private static final String TAG = "MediaPlayerSoundManager";
>
> > > > private Context context;
> > > > private MediaPlayerPool pool;
> > > > private HashMap<Integer, Integer> soundResourceMap;
>
> > > > public MediaPlayerSoundManager(Context context) {
> > > > this.context = context;
> > > > this.pool = new MediaPlayerPool(context,
> > > > AudioManager.STREAM_MUSIC);
> > > > this.soundResourceMap = new HashMap<Integer, Integer>();
> > > > }
>
> > > > public void init() {
> > > > release();
> > > > pool.addMedia(R.raw.sound_1, 2);
> > > > soundResourceMap.put(SOUND_1, R.raw.sound_1);
> > > > }
>
> > > > public void playSound(int soundId) {
> > > > int resourceId = getResourceId(soundId);
> > > > if (pool.hasMedia(resourceId)) {
> > > > pool.playMedia(resourceId);
> > > > } else {
> > > > playOneShotSound(resourceId);
> > > > }
> > > > }
>
> > > > private int getResourceId(int soundId) {
> > > > Integer resourceId = soundResourceMap.get(soundId);
> > > > if (resourceId == null) {
> > > > Log.e(TAG, "No resource found for soundId " +
> > > > soundId);
> > > > }
> > > > return resourceId;
> > > > }
>
> > > > private void playOneShotSound(int resourceId) {
> > > > MediaPlayer mp = MediaPlayer.create(context,
> > > > resourceId);
> > > > mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
> > > > mp.start();
> > > > mp.setOnCompletionListener(new
> > > > MediaPlayer.OnCompletionListener() {
> > > > public void onCompletion(MediaPlayer arg0) {
> > > > arg0.release();
> > > > }
> > > > });
> > > > }
>
> > > > public void release() {
> > > > pool.release();
> > > > soundResourceMap.clear();
> > > > }
>
> > > > }
>
> > > > On Nov 10, 10:04 pm, plusminus <[EMAIL PROTECTED]> wrote:
>
> > > > > Hi all,
>
> > > > > any ideas on how to implement a kind of OnCompletionListener ?
> > > > > As I want to queue 2 sounds after each other :/
>
> > > > > Any help appreciated.
>
> > > > > Best Regards,
> > > > > plusminus
>
> > > > > On 15 Okt., 08:47, Robert Green <[EMAIL PROTECTED]> wrote:
>
> > > > > > I just read the whole discussion. All I can say is... What were
> > > > > > they
> > > > > > thinking?? How is a developer supposed to be able to generate or
> > > > > > synthesize audio real time? These are important apps. Just look at
> > > > > > the guitar or harmonica app for the iPhone. Those are very popular
> > > > > > and do exactly that.
>
> > > > > > I'm just dumbfounded that the API developers don't provide such
> > > > > > basic
> > > > > > functionality as setting a byte stream datasource for a media
> > > > > > player.
> > > > > > Media players also are not adequate at all for games other than
> > > > > > providing the background music. Games often times have small
> > > > > > samples
> > > > > > that are played very often and need to be layered on each other.
> > > > > > Maintaining a media player pool seems very heavy and cumbersome just
> > > > > > to achieve this, not to mention you may end up with a 100 media
> > > > > > players if you have 30 different samples and estimate that it would
> > > > > > be
> > > > > > possible to play 3 at a time of each.
>
> > > > > > Another problem is that for racing, flying and other games which
> > > > > > have
> > > > > > an "engine" sound, it's not possible to get the pitch of the engine
> > > > > > to
> > > > > > match the speed shown on the game without being able to change the
> > > > > > sampling rate of the sound. I usedSoundPoolfor that because it
>
> ...
>
> read more ยป
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---