Java android程序中的声音不会';行不通
早上好,我一直在为我的android程序编写代码,我试着在这里用这些代码播放音乐android最低版本是2.2,最高版本是4.2.2,也使用eclipse来做这件事,设备模拟器是nexus one 这在全球范围内Java android程序中的声音不会';行不通,java,android,audio,Java,Android,Audio,早上好,我一直在为我的android程序编写代码,我试着在这里用这些代码播放音乐android最低版本是2.2,最高版本是4.2.2,也使用eclipse来做这件事,设备模拟器是nexus one 这在全球范围内 MediaPlayer Sound; 这是在setContentView下的 Sound = MediaPlayer.create(Splash.this, R.raw.kalimba); Sound.start(); 这就是全部代码 import andr
MediaPlayer Sound;
这是在setContentView下的
Sound = MediaPlayer.create(Splash.this, R.raw.kalimba);
Sound.start();
这就是全部代码
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity {
MediaPlayer Sound;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Sound = MediaPlayer.create(Splash.this, R.raw.kalimba);
Sound.start();
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
} catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent openStartingPoints = new Intent("com.mysampleapp.simplybel.MainActivity");
startActivity(openStartingPoints);
}//this is the end for the finally
}//this is the end for the run
};//this is the end for the thread timer
timer.start();
}//this is the end for the oncreate
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Sound.release();
finish();
}
}
有人能帮我做这件事吗?可能是出于你的意图。你到底想用这个意图做什么 显式意图的正确语法如下所示。例如
Intent openStartingPoints=新的Intent(上下文,MainActivity.class)代码>和上下文必须在线程之外,如上下文
作为全局变量声明,并使用context=this对其进行实例化将其设置为当前活动的上下文
另一个建议是,应始终以驼峰大小写命名变量名,因此第一个字母应为小写
如果这改变了什么,请告诉我。除此之外,我看不出提供的代码有任何问题