null pointer exception rtsp video

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();
    }
}

Answers


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)


Need Your Help

gcc reverse_iterator comparison operators missing?

c++ gcc stl iterator

I am having a problem using const reverse iterators on non-const containers with gcc. Well, only certain versions of gcc.