1

I have a video that I save to .../Movies/MyApp/abcde.mp4. So I know where it is. When I load it through my app using an implicit intent to ACTION_GET_CONTENT, the path is returned as content:/media/external/video/media/82 when I do

data.getData().toString()

The problem with that path is that it works when I try to access it with MediaRecorder as

mVideoView.setVideoURI(Uri.parse(mVideoStringPath))

However if I try to convert it to a path in another thread (for a job queue), the file is not found

new File(mVideoStringPath)

when I use the technique (copy and paste) described at How to get file path in onActivityResult in Android 4.4, still get the error

java.lang.RuntimeException: Invalid image file

Also per my logging, the new technique shows the path to the video as

video path: /storage/emulated/0/Movies/MyApp/abc de.mp4

notice the space in abc de.mp4. that indeed is the name of the file. And the phone's camera app has no trouble playing

Community
  • 1
  • 1
Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199

2 Answers2

0

However if I try to convert it to a path in another thread (for a job queue), the file is not found

That is because it is not a path to a file. It is a Uri, which is an opaque handle to some data.

How to get actual path to video from onActivityResult

You don't. You use the Uri. There is no requirement that the Uri point to a file. There is no requirement that the Uri, if it happens to represent a file, represent one that you have direct filesystem access to.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
-2

you need to escape the space the the file path in order to construct a File object from it.

filepath.replace(" ", "\\ "); 
pgiitu
  • 1,671
  • 1
  • 15
  • 23