gpt4 book ai didi

android - Mp3 无法在 Android 中播放

转载 作者:行者123 更新时间:2023-11-30 04:28:52 24 4
gpt4 key购买 nike

我创建了一个有声音的简单启动画面(mp3)

    package in.isuru.Hello;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;

public class Splash extends Activity {


MediaPlayer player;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//splash is a xml layout
setContentView(R.layout.splash);
//haha is a mp3 file.
player = MediaPlayer.create(Splash.this, R.raw.haha);
player.start();
//Timer to pause 5 seconds before go to next intent
Thread timer = new Thread(){
public void run(){
try{
//player starts playing mp3 file
sleep(5000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent openStartingPoint = new Intent("in.isuru.HELLO");
startActivity(openStartingPoint);
}
}
};
timer.start();
}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
player.release();
finish();
}



}

我试过了 android MediaPlayer not playing mp3 file也是,但没有用。我也查阅了 Android 文档。但似乎也无济于事。

最佳答案

player.prepare(); 放在 player.start(); 之前

看看是否可行

关于android - Mp3 无法在 Android 中播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8071007/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com