我试图在按钮点击后设计Android中的简单代码播放视频,但我遇到了未知问题。我目前的项目文件如下。我现在很无能为力。请指出一件事或解决这个问题。再次感谢!
public class VideoActivity extends Activity {
VideoView video;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
play = (Button)findViewById(R.id.button1);
play.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
myVideoView.setVideoPath("/mnt/usb_storage/vivek.3gp");
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();
myVideoView.start();
}
});
}
}
答案 0 :(得分:0)
btnPlay.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
try
{
videoView.setVideoPath(videoPath);
videoView.setMediaController(new MediaController(Applicaion Context or YourActivity.this));
videoView.start();
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("Error in btnInfo Click -->"+e.toString());
}
}
});
//BtnPlay