播放MP4视频,界面响应太慢
大家好
我写了一个视频播放器,在播放mp4视频的时候,界面响应很慢,大概需要5-6秒的时间。界面用的是lwuit库,当界面响应的时候,视频又会变得不流畅,请问什么原因,怎么解决?
核心代码:
//play the media
public void startToPlay() {
Thread t = new Thread(this);
t.start();
}
public void run() {
if (this.logo != null) {
this.removeLogo();
}
try {
this.pd.recognizeEncoding();
} catch (Exception e) {
ToolUtil.showErrorInfo(ResUtil.MediaNotSupportException, e.toString());
}
int rv;
//if the media is audio
if (this.pd.isAudio()) {
rv=this.initMI();
} else {
rv=this.initMC();//this function includes Manager.createPlayer player.realize() player.prefetch
}
//if the interface successes in initialization
if(rv==0)
{
if (!this.pd.isAudio()) {
this.fsBn.setEnabled(true);
}
this.playBn.setEnabled(true);
this.pd.play();//this function includes player.start()
}
}
(player 是指 mmapi里的 Player类的一个实例)
我觉得player.start()会自己创建一个新的线程来播放,这里我自己创建的新线程只是避免了再视频启动时不会冻结界面响应,但是我的问题是在视频播放的过程中,界面响应太慢,所以个人猜测原因在于mp4视频太耗cpu资源,再加上我使用了java界面(本身就有点耗资源),所以才会出现这种问题。但是我没办法确认,希望遇到过这种问题的高手给我点建议,谢谢。