MediaPlayer setDataSource with uristring causes NullPointerException

168 views Asked by At

Hey Dev's, I'm facing a problem with my Android App which is live on the google play store and keeps crashing on different devices and versions. "Caused by java.lang.NullPointerException uriString" on this file VideoPlayerActivity.onCreate (VideoPlayerActivity.java:74)

Please help me to solve this error, it's effect on my app ratings and user experience

Error image from Firebase Crashltics error img

     public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_player);
        SurfaceView surfaceView = findViewById(R.id.videoSurface);
        this.surfaceView = surfaceView;
        surfaceView.getHolder().addCallback(this);
        Bundle extras = getIntent().getExtras();
        this.filepath = extras.getString("PathVideo");
        this.fromStreaming = extras.getString("fromStreaming");
        mediaPlayer = new MediaPlayer();
        this.videoControllerView = new VideoControllerView(this);
        getWindow().setFlags(1024, 1024);

        try {
            if (this.fromStreaming == null) {
                // this is line 74 
                mediaPlayer.setDataSource(this.filepath);
            } else {
                mediaPlayer.setDataSource(getApplicationContext(), Uri.parse(this.filepath));
            }
            mediaPlayer.setOnPreparedListener(this);
        } catch (IllegalArgumentException | IllegalStateException | IOException | SecurityException e) {
            e.printStackTrace();
        }

        ImageView imageView = findViewById(R.id.img_View_Close);
        this.back = imageView;
        imageView.setOnClickListener(view -> {
            VideoPlayerActivity.mediaPlayer.stop();
            VideoPlayerActivity.this.onBackPressed();
        });
    }
0

There are 0 answers