我無法在我的Mac的Android模擬器中聽到任何聲音。有時候,我真的很少聽到它。我給你我的聲音管理器代碼。但我認爲它的配置問題聽不到聲音Android模擬器Mac
我從他們說它的工作頁面複製代碼。而且我已經嘗試過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;
}
}
嗨@Anna,我在Macbook Pro 2009和iMac 2011年底試用它沒有。但就像我說我只是重新安裝和工作 – Edig
@Anna我添加了-useaudio開關,並嘗試包括'android.media.MediaPlayer'導入,但它一旦輸入';'就從IDE中消失結束該行。不知道這是否意味着它已經加載。無論哪種方式,它都不會改變模擬器無法播放聲音。任何時候我做一些需要聲音的東西,logcat都會吐出關於找不到揚聲器的消息。有任何想法嗎? – dbconfession