带有mp3音调的Android启动活动

时间:2012-10-05 18:53:46

标签: android multithreading android-asynctask mp3 splash

在我的Android应用程序中,我希望在加载启动活动时播放mp3音。我已经完成了我的动画启动活动。我的代码。请某人帮我播放mp3音。

package com.bni.www;

 import android.app.Activity;
 import android.content.Intent;
 import android.graphics.PixelFormat;
 import android.os.Bundle;
 import android.os.CountDownTimer;
 import android.view.Window;
 import android.view.WindowManager;
 import android.view.animation.Animation;
 import android.view.animation.AnimationUtils;
 import android.widget.ImageView;
 import android.widget.LinearLayout;


public class Main extends Activity {



 public void onAttachedToWindow() {
     super.onAttachedToWindow();
     Window window = getWindow();
     window.setFormat(PixelFormat.RGBA_8888);
    }


   @Override
   public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

 setContentView(R.layout.spalsh);
 CountDown _tik;
 _tik=new CountDown(12000,100,this,Login.class);
 //Intent intent=new Intent(Main.this,Login.class);   
 _tik.start();
 StartAnimations();
 //startActivity(intent);
}
  private void StartAnimations() {
 Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
 anim.reset();
 LinearLayout l=(LinearLayout) findViewById(R.id.lin_lay);
 l.clearAnimation();
 l.startAnimation(anim);

 anim = AnimationUtils.loadAnimation(this, R.anim.translate);
 anim.reset();
 ImageView iv = (ImageView) findViewById(R.id.logo);
 iv.clearAnimation();
 iv.startAnimation(anim);

   }



 }


 class CountDown extends CountDownTimer{
 private Activity _act;
 private Class _cls;
 public CountDown(long millisInFuture, long countDownInterval,Activity act,Class cls) {
 super(millisInFuture, countDownInterval);
 _act=act;
 _cls=cls;
 }
 @Override
 public void onFinish() {
 _act.startActivity(new Intent(_act,_cls));
 _act.finish();
 }
@Override
public void onTick(long millisUntilFinished) {

 }
}

1 个答案:

答案 0 :(得分:0)

使用此代码播放音频。

mp = MediaPlayer.create(yourclassname.this, R.raw.mysound);
                        mp.setOnCompletionListener(new OnCompletionListener() {

                            @Override
                            public void onCompletion(MediaPlayer mp) {
                                // TODO Auto-generated method stub
                                mp.release();
                            }

                        });   
                        mp.start();