我正在编写其中一项活动能够播放视频文件的应用程序。我录制了视频,但是当尝试播放时开始出现问题。活动开始并第一次正常播放视频。然后我按后退按钮,返回上一个活动,选择视频(相同或其他),视频播放活动再次进入,所有视图(按钮,搜索栏等)显示,但视频不显示。我再次返回,选择视频,打开视频播放活动,视频再次正常播放。所以它每秒钟播放一次。我试图调试但找不到问题所在,任何帮助将不胜感激。活动代码在下面,eclipse 的 logCat 输出也在下面。
public class FightPlayerActivity extends Activity implements OnSeekBarChangeListener, SurfaceHolder.Callback, OnPreparedListener {
private MediaPlayer mp=null;
private SeekBar seekBar;
private String filePath;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Toast.makeText(this,"Create ", 2000).show();
setContentView(R.layout.fight_player);
filePath=getIntent().getStringExtra("filename");
filePath=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)+"/FightAll_BJJ_Scoring/"+filePath;
Toast.makeText(this,filePath, 2000).show();
// seek bar
seekBar=(SeekBar) findViewById(R.id.seek_bar);
seekBar.setOnSeekBarChangeListener(this);
try {
SurfaceView sv=(SurfaceView) findViewById(id.video_preview);
SurfaceHolder sh=sv.getHolder();
sh.addCallback(this);
sh.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
}
public void onStop(View view)
{
super.onStop();
mp.stop();
mp.reset();
mp.release();
}
public void onStart(View view)
{
super.onStart();
}
public void stop(View view)
{
mp.stop();
}
public void pause(View view)
{
mp.pause();
}
public void play(View view)
{
mp.start();
}
public void surfaceCreated(SurfaceHolder holder) {
try {
mp=new MediaPlayer();
mp.setDataSource(filePath);
mp.setDisplay(holder);
mp.setOnPreparedListener(this);
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
public void onPrepared(MediaPlayer mediaplayer) {
mp.start();
seekBar.setMax(mp.getDuration());
}
public void onProgressChanged(SeekBar sb,int progress,boolean fromUser)
{
//Toast.makeText(this, progress, 2000).show();
mp.seekTo(progress);
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
onProgressChanged(seekBar,seekBar.getProgress(),true);
}
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
并在下面登录:
08-19 18:26:39.325: E/MediaPlayer(7057): message received msg=200, ext1=1, ext2=44
08-19 18:26:39.325: W/MediaPlayer(7057): info/warning (1, 44)
08-19 18:26:39.325: E/MediaPlayer(7057): callback application
08-19 18:26:39.325: E/MediaPlayer(7057): back from callback
08-19 18:26:39.325: E/MediaPlayer(7057): message received msg=1, ext1=0, ext2=0
08-19 18:26:39.325: E/MediaPlayer(7057): callback application
08-19 18:26:39.325: E/MediaPlayer(7057): back from callback
08-19 18:26:39.361: E/MediaPlayer(7057): message received msg=5, ext1=176, ext2=144
08-19 18:26:39.361: E/MediaPlayer(7057): callback application
08-19 18:26:39.365: E/MediaPlayer(7057): back from callback
08-19 18:26:39.380: I/MediaPlayer(7057): Info (1,44)
08-19 18:26:45.661: E/MediaPlayer(7057): message received msg=200, ext1=1, ext2=44
08-19 18:26:45.661: W/MediaPlayer(7057): info/warning (1, 44)
08-19 18:26:45.661: E/MediaPlayer(7057): callback application
08-19 18:26:45.661: E/MediaPlayer(7057): back from callback
08-19 18:26:45.661: E/MediaPlayer(7057): message received msg=1, ext1=0, ext2=0
08-19 18:26:45.661: E/MediaPlayer(7057): callback application
08-19 18:26:45.661: E/MediaPlayer(7057): back from callback
08-19 18:26:45.708: I/MediaPlayer(7057): Info (1,44)
08-19 18:26:45.779: W/IMediaDeathNotifier(7057): media server died
08-19 18:26:45.779: E/MediaPlayer(7057): message received msg=100, ext1=100, ext2=0
08-19 18:26:45.779: E/MediaPlayer(7057): error (100, 0)
08-19 18:26:45.779: E/MediaPlayer(7057): callback application
08-19 18:26:45.779: E/MediaPlayer(7057): back from callback
08-19 18:26:45.779: E/MediaPlayer(7057): message received msg=100, ext1=100, ext2=0
08-19 18:26:45.779: E/MediaPlayer(7057): error (100, 0)
08-19 18:26:45.779: E/MediaPlayer(7057): callback application
08-19 18:26:45.779: E/MediaPlayer(7057): back from callback
08-19 18:26:45.779: W/Camera(7057): Camera server died!
08-19 18:26:45.786: E/MediaPlayer(7057): Error (100,0)
08-19 18:26:45.790: E/MediaPlayer(7057): Error (100,0)