How to get actual path to video from onActivityResult

时间:2015-09-30 23:21:20

标签: android video uri filepath

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

2 个答案:

答案 0 :(得分:0)

  

但是,如果我尝试将其转换为另一个线程中的路径(对于作业队列),则找不到该文件

那是因为它不是文件的路径。它是Uri,它是某些数据的不透明句柄。

  

如何从onActivityResult获取视频的实际路径

你没有。您使用Uri。不要求Uri指向文件。如果Uri恰好代表文件,则不要求String UserInput = new Scanner(System.in).next(); GradesNonInt = Arrays.asList(UserInput.replaceAll("\\s","").split(",")); System.out.println(GradesNonInt.size()); 代表您可以直接访问文件系统的文件。

答案 1 :(得分:-2)

你需要转义文件路径的空间,以便从中构造一个File对象。

filepath.replace(" ", "\\ "); 
相关问题