Eduardo Iglesias
Eduardo Iglesias

Reputation: 1066

Can't hear sound Android Simulator Mac

I can't hear any sound in my Android Simulator in my Mac. Some times, verily little time I can hear it. I give you my code of my Sound Manager. But i think its configuration problems

I copy the code from a page that they said it works. And i already try about 5 different codes and none works. My sound are in WAV game: 100k menu 800k

Thanks

    import java.util.HashMap;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;


public class SoundManager {

    static private SoundManager _instance;
    private static SoundPool mSoundPool; 
    private static HashMap<Integer, Integer> mSoundPoolMap; 
    private static AudioManager  mAudioManager;
    private static Context mContext;

    private SoundManager()
    {   
    }

    /**
     * Requests the instance of the Sound Manager and creates it
     * if it does not exist.
     * 
     * @return Returns the single instance of the SoundManager
     */
    static synchronized public SoundManager getInstance() 
    {
        if (_instance == null) 
          _instance = new SoundManager();
        return _instance;
     }

    /**
     * Initialises the storage for the sounds
     * 
     * @param theContext The Application context
     */
    public static  void initSounds(Context theContext) 
    { 
         mContext = theContext;
         mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
         mSoundPoolMap = new HashMap<Integer, Integer>(); 
         mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);        
    } 

    /**
     * Add a new Sound to the SoundPool
     * 
     * @param Index - The Sound Index for Retrieval
     * @param SoundID - The Android ID for the Sound asset.
     */
    public static void addSound(int Index,int SoundID)
    {
        mSoundPoolMap.put(Index, mSoundPool.load(mContext, SoundID, 1));
    }

    /**
     * Loads the various sound assets
     * Currently hard coded but could easily be changed to be flexible.
     */
    public static void loadSounds()
    {
        mSoundPoolMap.put(1, mSoundPool.load(mContext, R.raw.menu, 1));
        mSoundPoolMap.put(2, mSoundPool.load(mContext, R.raw.game, 1));     
    }

    /**
     * Plays a Sound
     * 
     * @param index - The Index of the Sound to be played
     * @param speed - The Speed to play not, not currently used but included for compatibility
     */
    public static void playSound(int index,float speed) 
    {       
             float streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); 
             streamVolume = streamVolume / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
             mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, speed); 
    }

    /**
     * Stop a Sound
     * @param index - index of the sound to be stopped
     */
    public static void stopSound(int index)
    {
        mSoundPool.stop(mSoundPoolMap.get(index));
    }

    public static void cleanup()
    {
        mSoundPool.release();
        mSoundPool = null;
        mSoundPoolMap.clear();
        mAudioManager.unloadSoundEffects();
        _instance = null;

    }


}

Upvotes: 1

Views: 2513

Answers (2)

Anna Billstrom
Anna Billstrom

Reputation: 2492

Basically, you have to set a flag in the config settings to tell it what kind of audio to output, and what device. It's a pain. I wrote about it here:

http://www.banane.com/2012/01/11/joy-of-android-playing-sound/

That worked on my old MacBook. Just upgraded to a Mac Air and the solution has changed, not sure, but -audio is the solution now. I'll post here when I get it working.

Upvotes: 1

Eduardo Iglesias
Eduardo Iglesias

Reputation: 1066

I SOLVED IT,

Just re-install all the eclipse and SDK. I try in another computer and works fine. The same code

Upvotes: 0

Related Questions