android - Android 模拟器 Mac 听不到声音

标签 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;

    }


}

最佳答案

基本上,您必须在配置设置中设置一个标志来告诉它要输出哪种音频以及使用什么设备。这很痛苦。我在这里写道:

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

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

关于android - Android 模拟器 Mac 听不到声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8176403/

相关文章:

android - 解析和存储电子书内容,sqlite 索引

android - 如何在 Android 的服务类中实现 BroadcastReceiver?

java - 后退按钮在模拟器上工作,但在 Android 设备上不起作用

android - 最新的 com.google.android.gms for google play services revision 6

android - 在 INTEL Android (Android-x86) 上安装 Flash 或 AIR?

android - 如何在 android 主屏幕 ListView 小部件中加载项目?

android - 当我使用 proguard 时,谷歌地图没有加载

安卓。模拟器突然出问题,物理设备工作正常

Android应用程序在按钮单击时调用号码

android - 不支持的操作异常 : Can't convert to dimension: type=0x1