【问题标题】:Sound in android programs doesn't workandroid程序中的声音不起作用
【发布时间】:2013-07-25 19:42:24
【问题描述】:

美好的一天,我一直在为我的 android 程序做一些编码,我尝试在这里用这段代码播放音乐 android 最低版本是 2.2,最高版本是 4.2.2 也使用 eclipse 和设备模拟器是联结一号

地球上的这个

    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();
}


}

有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: java android audio


    【解决方案1】:

    它可能来自您的意图。你到底想用这个意图做什么?

    显式意图的正确语法应该类似于intent tutorial。例如, Intent openStartingPoints=new Intent(context,MainActivity.class); 和 context 必须像 Context context; 这样的线程外部作为全局变量声明,并在 onCreate() 内部使用 context=this; 对其进行实例化,以将其设置为当前活动的上下文。

    作为另一个建议,您应该始终以驼峰式命名变量名称,因此第一个字母应该小写。

    如果这有什么改变,请告诉我。除此之外,我看不到提供的代码有任何问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多