Question

I am trying to read a rtsp stream from an ipcam. The url perfectly works in VLC but I get a nullPointerException when I try to launch it with a videoView.

java.lang.NullPointerException
at com.xxx.myApp.PlayVideo.PlayVideo(PlayVideo.java:63)
at com.xxx.myApp.PlayVideo.access$0(PlayVideo.java:48)
at com.xxx.myApp.PlayVideo$1.onClick(PlayVideo.java:41)
at android.view.View.performClick(View.java:4240)
at android.view.View$PerformClick.run(View.java:17721)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

In my mainActivity (I only got one). The rtsp file is exactl the same than used with VLC, and it worked. I tried to add single quotes to the username, like this : ...user='user'..., without success.

private void PlayVideo(){
    try{            

        String rtspPath = "rtsp://x.x.x.x:554/user=user&password=&channel=1&stream=0.sdp?";
        getWindow().setFormat(PixelFormat.TRANSLUCENT);

        videoView = (VideoView)findViewById(R.layout.activity_play_video);

        MediaController mediaController = new MediaController(PlayVideo.this);
        mediaController.setAnchorView(videoView);

        Uri videoPath = Uri.parse(rtspPath);
        System.out.println(videoPath);
        videoView.setMediaController(mediaController);
        //videoView.setVideoURI(videoPath);
        videoView.setVideoPath(rtspPath);
        videoView.requestFocus();

        videoView.setOnPreparedListener(new OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mp) {
                progressDialog.dismiss();
                videoView.start();
            }
        });


    }catch(Exception e){
        System.out.println("Message : " + e.getMessage());
        e.printStackTrace();
        progressDialog.dismiss();
        System.out.println("Video Play Error : "+e.toString());
        finish();
    }
}
Was it helpful?

Solution

Instead of this..

videoView = (VideoView)findViewById(R.layout.activity_play_video);

Try this..

videoView = (VideoView)findViewById(R.id.videoView_id);

You cannot findViewById as layout

Description on findViewById(int id)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top