我尝试播放来自 R.raw 的声音。在 Thread/Runnable 中 但我无法让它工作。
new Runnable(){ public void run() { //this is giving me a NullPointerException, because getBaseContext is null MediaPlayer mp = MediaPlayer.create( getBaseContext(), R.raw.soundfile); while (true) { if (something) play something } }
如何在 run 方法中获取真正的 Context?无论我尝试什么,它都是空的。或者有更好的方法吗?
最佳答案
您还应该能够使用 MainActivity.this
从外部类获取 this 引用。
关于android - Runnable 中的上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3875391/