我创建像卡拉OK这样的应用程序。但是,当我的应用播放 mp3/aac 超过 1 分钟时。我创建的这些文本不显示。然而 setText(); 1分钟以下正常显示。我该如何解决。我明天必须派老师来。代码很简单。非常感谢。
public class Okkaraoke extends Activity implements MediaPlayerControl,OnClickListener {
private MediaController mMediaController;
private MediaPlayer mMediaPlayer;
Handler mHandler = new Handler();
public static TextView subtitles2,subtitles21;
@SuppressLint("HandlerLeak")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.myapp2);
subtitles2 = (TextView) findViewById(R.id.subs2);
subtitles21 = (TextView) findViewById(R.id.subs21);
mMediaPlayer = new MediaPlayer();
mMediaController = new MediaController(this)
mMediaController.setMediaPlayer(Okekaraoke.this);
mMediaController.setAnchorView(findViewById(R.id.AudioView2));
mMediaController.setPrevNextListeners(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Next button clicked
Intent intent = new Intent(Okkarake.this, Show1.class);
startActivity(intent);
}
}, new View.OnClickListener() {
@Override
public void onClick(View v) {
// Previous button clicked
Intent intent = new Intent(Okkaraoke.this, Main.class);
startActivity(intent);
}
});
try {
mMediaPlayer.setDataSource(this, Uri
.parse("android.resource://com.app.suadmon/raw/sorry"));
mMediaPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
}
mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
final int currentPos = mMediaPlayer.getCurrentPosition();
if (mMediaPlayer.getCurrentPosition() < 28715) {
subtitles2.setText("Let's start");
subtitles21.setText("...................");
}else if(mMediaPlayer.getCurrentPosition()< 33134) {
subtitles2.setText("Oh my god");
subtitles21.setText("Text Displaying");
}else if(mMediaPlayer.getCurrentPosition() < 39811) {
subtitles2.setText("function is green");
subtitles21.setText("Text Displaying");
}else if(mMediaPlayer.getCurrentPosition()< 44294) {
subtitles2.setText("Working..");
subtitles21.setText("Text Displaying");
}else if(mMediaPlayer.getCurrentPosition()< 50940) {
subtitles2.setText("Normally");
subtitles21.setText("Text Displaying");
}else if(mMediaPlayer.getCurrentPosition()< 55387) {
subtitles2.setText("Text can show normally");
subtitles21.setText("Text Displaying");
}else if(mMediaPlayer.getCurrentPosition()< 103807) {
subtitles2.setText("Working");
subtitles21.setText("Text Displaying");
}else if(mMediaPlayer.getCurrentPosition()<108173) {
subtitles2.setText("Text is not show up from here !");
subtitles21.setText("Text's not Display");
} else if(mMediaPlayer.getCurrentPosition()< 112646) {
subtitles2.setText("All text from here can't show");
subtitles21.setText("Text's not Display");
} else if(mMediaPlayer.getCurrentPosition()< 119555) {
subtitles2.setText("TextView din't show up");
subtitles21.setText("Text's not Display");
} else if (mMediaPlayer.getCurrentPosition()< 130356) {
subtitles2.setText("..................");
subtitles21.setText("Text's not Display");
} else if (mMediaPlayer.getCurrentPosition()< 138812) {
subtitles2.setText("************");
subtitles21.setText("Text's not Display");
} else if (mMediaPlayer.getCurrentPosition()< 147369) {
subtitles2.setText("Text's not Display");
subtitles21.setText("*************");
}
mHandler.sendEmptyMessageDelayed(0, 1);
}
};
mHandler.sendEmptyMessage(0);
mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mHandler.post(new Runnable() {
public void run() {
mMediaController.show(0);
// mMediaPlayer.reset();
mMediaPlayer.start();
}
});
}
});
mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
Intent newAc = new Intent(Okkaraoke.this, Show.class);
startActivity(newAc);
}
});
}
我有音乐 03.45 分钟。在handleMassege() 中。我尝试最终 int/long sPos = mMediaPlayer.getCurrentPosition(); 也。但是,这行不通。setText 与上面的代码相同。非常感谢。