新手学习Android开发,参考书为《第一行代码》,关于视频播放那一段一直调试不过去。播放视频一直有个错误,在google里翻了好久,都没有解决,还请各位给点指导。
主要错误提示如下:
MediaPlayer﹕ Couldn't open file on client side, trying server side
代码如下
public class MainActivity extends Activity implements View.OnClickListener{
private VideoView videoView;
private Button play;
private Button pause;
private Button replay;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
play=(Button)findViewById(R.id.play);
pause=(Button)findViewById(R.id.pause);
replay=(Button)findViewById(R.id.replay);
videoView=(VideoView)findViewById(R.id.video_view);
play.setOnClickListener(this);
pause.setOnClickListener(this);
replay.setOnClickListener(this);
initVideoPath();
}
private void initVideoPath(){
File file=new File(Environment.getExternalStorageDirectory(),"record.mp4");
videoView.setVideoPath(file.getPath());
}
@Override
public void onClick(View v){
switch (v.getId()){
case R.id.play:
if (!videoView.isPlaying()){
videoView.start();
}
break;
case R.id.pause:
if (videoView.isPlaying()){
videoView.pause();
}
break;
case R.id.replay:
if (videoView.isPlaying()){
videoView.resume();
}
break;
}
}
@Override
protected void onDestroy(){
super.onDestroy();
if (videoView!=null){
videoView.suspend();
}
}
}
initVideoPath()里面路径获取,"record.mp4"前面要加斜杠,不然找不到你写的这个路径,前面是一个文件夹,斜杠后加文件名才能找到你的文件呀。
我看了一下,你的问题很可能是sd卡的路径没找对。
你解决的话,我们可以一起讨论一下。