无法听到Android Emulator Mac的声音

时间:2011-11-18 00:41:31

标签: android android-emulator

我的Mac上的Android模拟器中听不到任何声音。有时候,我几乎没有时间能听到它。我给你的声音管理器代码。但我认为它的配置问题

我从他们认为有效的页面复制代码。我已经尝试了5种不同的代码,但都没有。我的声音在WAV游戏中:100k菜单800k

由于

    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;

    }


}

2 个答案:

答案 0 :(得分:1)

基本上,你必须在配置设置中设置一个标志,告诉它输出什么样的音频,以及什么设备。这是一种痛苦。我在这里写到:

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

这适用于我原来的MacBook。刚升级到Mac Air并且解决方案已经改变,不确定,但是-audio现在是解决方案。当我开始工作时,我会发布在这里。

答案 1 :(得分:0)

我解决了它,

重新安装所有的eclipse和SDK。我尝试在另一台电脑上工作正常。相同的代码