这里我正在做代码,当我点击显示视频按钮时,它应该打开一个对话框,我们可以在其中运行任何大小的视频。下面是我的源代码
源代码是: -
public class MainActivity extends Activity {
private Button videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
}
private void initViews() {
buttonvideoView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
final Dialog dialog = new Dialog(MainActivity.this, android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.activity_videoview);
String STREAM_URL = "http://videofry.com/mp4/34822/Yaar_Bathere-Alfaaz(VideoFRY.Com).mp4";
Uri uri = Uri.parse(STREAM_URL);
VideoView mVideo = (VideoView) findViewById(R.id.videoView);
mVideo.setVideoURI(uri);
MediaController controller = new MediaController(MainActivity.this);
controller.setAnchorView(mVideo);
mVideo.setKeepScreenOn(true);
mVideo.setMediaController(controller);
mVideo.start();
dialog.show();
}
videoView = (Button)findViewById(R.id.video_videw);
videoView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, VideoActivity.class);
startActivity(intent);
}
});
}
}
我尝试了很多技巧,但它没有帮助。它显示空指针异常。如果你建议在对话框中运行视频的任何其他方法,那么也应该高度赞赏。
04-08 11:50:17.630: E/AndroidRuntime(1058): FATAL EXCEPTION: main
04-08 11:50:17.630: E/AndroidRuntime(1058): java.lang.NullPointerException
04-08 11:50:17.630: E/AndroidRuntime(1058): at com.example.sampletest.MainActivity$1.onClick(MainActivity.java:37)
04-08 11:50:17.630: E/AndroidRuntime(1058): at android.view.View.performClick(View.java:3480)
04-08 11:50:17.630: E/AndroidRuntime(1058): at android.view.View$PerformClick.run(View.java:13983)
04-08 11:50:17.630: E/AndroidRuntime(1058): at android.os.Handler.handleCallback(Handler.java:605)
04-08 11:50:17.630: E/AndroidRuntime(1058): at android.os.Handler.dispatchMessage(Handler.java:92)
04-08 11:50:17.630: E/AndroidRuntime(1058): at android.os.Looper.loop(Looper.java:137)
04-08 11:50:17.630: E/AndroidRuntime(1058): at android.app.ActivityThread.main(ActivityThread.java:4340)
04-08 11:50:17.630: E/AndroidRuntime(1058): at java.lang.reflect.Method.invokeNative(Native Method)
04-08 11:50:17.630: E/AndroidRuntime(1058): at java.lang.reflect.Method.invoke(Method.java:511)
04-08 11:50:17.630: E/AndroidRuntime(1058): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-08 11:50:17.630: E/AndroidRuntime(1058): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-08 11:50:17.630: E/AndroidRuntime(1058): at dalvik.system.NativeStart.main(Native Method)