我想在视频中播放视频文件,该文件显示在对话框中,完成后应关闭对话框。我读到了通过媒体控制器进行的操作,所以我有以下内容:
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)如何根据最大高度和重量控制此对话框的大小?
答案 0 :(得分:1)
您必须使用getApplicationContext()来获取上下文。 Context表示环境数据。看看这里:What is Context in Android?