我尝试从 SD 卡播放视频。这就是我尝试此代码的原因
public class VideoPlayActivity extends Activity {
private VideoView video;
private MediaController ctlr;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
setContentView(R.layout.main);
File clip=new File(Environment.getExternalStorageDirectory(),
"haha.mp4");
if (clip.exists()) {
video=(VideoView)findViewById(R.id.video);
video.setVideoPath(clip.getAbsolutePath());
ctlr=new MediaController(this);
ctlr.setMediaPlayer(video);
video.setMediaController(ctlr);
video.requestFocus();
video.start();
}
}
}
当我在 android 设备中运行此代码时,视频不只显示黑屏。当我断开手机并打开此项目时,视频播放。代码中的实际问题是什么?