VideoView Android 对话框中的 Completion Listener
VideoView Completion Listener inside a dialog box in Android
我想播放 videoview 中的一个视频文件,它显示在一个对话框中,完成后对话框应该关闭。我阅读了有关通过媒体控制器执行此操作的信息,因此我有以下内容:
final Dialog dialog = new Dialog(MyActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.MyCustomLayoutWithVideoView);
dialog.show();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
lp.copyFrom(dialog.getWindow().getAttributes());
dialog.getWindow().setAttributes(lp);
final VideoView videoview = (VideoView) dialog.findViewById(R.id.videoView);
Uri uri = Uri.parse(SoundFile);
**MediaController mc = new MediaController(this);
videoview.setMediaController(mc);**
videoview.start();
videoview.setVideoURI(uri);
videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp)
{
Toast.makeText(getApplicationContext(), "Msg", Toast.LENGTH_LONG).show();
}
});
1) 声明mediacontroller的部分是错误的..它无法获取上下文,上下文是什么?
2) 如何根据最大高度和重量控制此对话框的大小?
您必须使用 getApplicationContext() 来获取上下文。上下文代表环境数据。看这里:What is Context in Android?
我想播放 videoview 中的一个视频文件,它显示在一个对话框中,完成后对话框应该关闭。我阅读了有关通过媒体控制器执行此操作的信息,因此我有以下内容:
final Dialog dialog = new Dialog(MyActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.MyCustomLayoutWithVideoView);
dialog.show();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
lp.copyFrom(dialog.getWindow().getAttributes());
dialog.getWindow().setAttributes(lp);
final VideoView videoview = (VideoView) dialog.findViewById(R.id.videoView);
Uri uri = Uri.parse(SoundFile);
**MediaController mc = new MediaController(this);
videoview.setMediaController(mc);**
videoview.start();
videoview.setVideoURI(uri);
videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp)
{
Toast.makeText(getApplicationContext(), "Msg", Toast.LENGTH_LONG).show();
}
});
1) 声明mediacontroller的部分是错误的..它无法获取上下文,上下文是什么?
2) 如何根据最大高度和重量控制此对话框的大小?
您必须使用 getApplicationContext() 来获取上下文。上下文代表环境数据。看这里:What is Context in Android?