Search code examples
androidvideoandroid-mediaplayerandroid-video-playerandroid-videoview

Android Video view: Unable to play video files with '%' character in filename


I am trying to play a file example name : 'sample%20video.mp4' inside a 'VideoView'. The file does'nt play showing an error :

Can't play video

There is no problem with the video file, as it works fine when removing the '%' from the file name.

Note: When launching the video('sample%20video.mp4') from the file location using apps like 'Photos' , 'Video player' plays fine without any issue.

Anybody knows the reason for this kind of behavior??


Solution

  • Are you passing the filename to Uri.parse() without first calling Uri.encode()? If so then that could be the reason for the problem, you need to encode it first to handle any special characters:

    VideoView videoView = findViewById(R.id.videoView);
    videoView.setVideoURI(Uri.parse(Uri.encode(videofilepath)));