【问题标题】:Android splash activity with mp3 tone带有 mp3 音调的 Android 飞溅活动
【发布时间】:2012-10-05 18:53:46
【问题描述】:

在我的 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) {

 }
}

【问题讨论】:

    标签: android multithreading android-asynctask mp3 splash-screen


    【解决方案1】:

    使用此代码播放音频。

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

    【讨论】:

    • 我应该如何同时运行它。我的意思是当它加载启动活动时?
    • 你可以把它放在你的 startAnimations() 中
    • 是的,我也尝试过,但是播放 mp3 后会出现闪屏。现在我遇到了严重的问题。mp3 在我的模拟器中无法播放。昨天它运行良好,但今天它不起作用。这是什么原因?
    • 好的,在调用 startAnimations() 之前在 onCreate 方法中使用这段代码,并确保动画和 mp3 的长度相同。
    • 我的模拟器现在不能播放 mp3。我认为我的模拟器出错了。我应该怎么做才能避免这种情况?请帮我。谢谢你的回答
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多