11

我想在单击图像时出现的对话框中播放视频。视频无法播放,应用程序崩溃。这是我的代码:

image.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// custom dialog
final Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.introvid);
dialog.show();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.copyFrom(dialog.getWindow().getAttributes());
dialog.getWindow().setAttributes(lp);
final VideoView videoview = (VideoView) findViewById(R.id.surface_view);
Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.introvideo);
videoview.setVideoURI(uri);
videoview.start();
}
});

我的视频在 res/raw 文件夹中。它是一个 MP4 视频。

4

3 回答 3

3

试试这个,在你的代码中添加这个代码。我希望它能解决问题

final VideoView videoview = (VideoView) dialog.findViewById(R.id.surface_view);
于 2013-09-25T07:26:11.460 回答
2

我已经修改了你的代码,这是你修改后的代码:

    final Dialog dialog = new Dialog(yourclassname.this);// add here your class name
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.yourxml);//add your own xml with defied with and height of videoview
    dialog.show();
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lp.copyFrom(dialog.getWindow().getAttributes());
    dialog.getWindow().setAttributes(lp);
    uriPath= "android.resource://" + getPackageName() + "/" + R.raw.logo_animation;

    getWindow().setFormat(PixelFormat.TRANSLUCENT);
    Log.v("Vidoe-URI", uriPath+ "");
    mVideoView.setVideoURI(Uri.parse(uriPath));
    mVideoView.start();
于 2013-09-25T07:55:09.387 回答
0

添加您的代码。

dialog.findViewById(R.id.surface_view);

于 2015-10-20T04:42:19.307 回答