首先请注意,我是一个noob。Android,如何让这个工作?
我所试图做的事: 呼叫中的其他类中的代码从活动 一旦工作我要开始一个新的活动,并呼吁从那里代码(请告诉我如何多数民众赞成要做的事)
我工作过这个例如:http://stackoverflow.com/questions/7061594/loading-mp3s-into-the-sound-pool-in-android
当我点击按钮,它力眼下退出:(
我的代码:
class MyApp extends Application {
private static MyApp singleton;
private static SoundPool mSoundPool;
private HashMap<Integer, Integer> soundPoolMap;
public static final int A1 = 1;
@Override
public void onCreate() { // This onCreate is for this class
super.onCreate();
singleton = this;
mSoundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);// Just an example
soundPoolMap = new HashMap<Integer, Integer>();
soundPoolMap.put(A1, mSoundPool.load(MyApp.this, R.raw.a, 1));
}
public void playSound(int sound) {
AudioManager mgr = (AudioManager)MyApp.this.getSystemService(Context.AUDIO_SERVICE);
float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume = streamVolumeCurrent/streamVolumeMax;
mSoundPool.play(soundPoolMap.get(sound), volume, volume, 1, 0, 1f);
}
public static MyApp getInstance() {
return singleton;
}
public SoundPool getSoundPool() {
return mSoundPool;
}
}
public class TestAndroidGlobalsActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void next_activity(View v)
{
//MyApp.getInstance().getSoundPool().playSound(1);
MyApp.getInstance().playSound(1);
}
}
我的清单文件,如果你需要它:
http://pastebin.com/YHjgGPyd
谢谢!
Ryan
请增加一个堆栈跟踪。 – mibollma
什么是堆栈跟踪?我在哪里/如何添加它? – Ryan
stacktrace ==引起强制关闭的异常的整个输出。在Eclipse中查看LogCat窗口。 – elevine