내 Mac의 Android 시뮬레이터에서 소리가 들리지 않습니다. 약간의 시간, 나는 거의들을 수 없다. 내 Sound Manager에 대한 코드를 제공합니다. 하지만 그 구성 문제라고 생각합니다.소리가 들리지 않습니다. Android 시뮬레이터 Mac
나는 그것이 작동한다고 말하는 페이지에서 코드를 복사합니다. 그리고 나는 이미 약 5 개의 다른 코드를 시도하고 아무도 작동하지 않습니다. 내 소리가 WAV 게임에 : 100,000 메뉴 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 Late 2011에서 사용해보십시오. 아니요. 하지만 내가 말했듯이 둘 다 다시 설치하고 작업을했다. – Edig
@Anna -useaudio 스위치를 추가하고'android.media.MediaPlayer' 가져 오기를 시도했지만 IDE에서'; '를 입력하자마자 사라집니다. 라인을 끝내십시오. 이것이 이미로드되었음을 의미하는지 확실하지 않습니다. 어쨌든 에뮬레이터가 사운드를 재생할 수 없다는 사실은 바뀌지 않습니다. 그리고 소리를 내야 할 때마다 logcat은 연사를 찾을 수 없다는 메시지를 뱉어냅니다. 어떤 아이디어? – dbconfession