0

I'm getting media that's on the phone as mentioned here (using ContentResolver) but the path returned is of the form /storage/emulated/0/... and trying to use it for mediaPlayer.SetDataSource() yields a Java.IO.FileNotFoundException. I realize that this path is probably not a real path, but how do I get the real path from this path?

When I have an Asset in the project folder, the MediaPlayer works fine. But I can't get it to work with other files. I already set the permission for READ_EXTERNAL_STORAGE .

Though I rather have an answer in C#, An answer in Java would probably be enough.

EDIT

I've seen some answers dealing with similar things but they all assume I have a Uri. While the method above returns a string. And I haven't been successful in trying to convert it to a Uri so I can't even test those solutions.

Community
  • 1
  • 1
ispiro
  • 26,556
  • 38
  • 136
  • 291
  • "I realize that this path is probably not a real path" -- there is certainly nothing wrong with `/storage/emulated/0/`. Whether the file exists is another matter. "I already set the permission for READ_EXTERNAL_STORAGE ." -- I have no idea how Xamarin handles runtime permissions, but you need that too, most likely. Also note that the approach that you are using will not work for all media (e.g,. media on removable storage). – CommonsWare Jan 01 '17 at 22:38
  • @CommonsWare It's not on removable media. It's a file I put on the phone using a USB cable and Windows Explorer. And the path is returned as `Data` by the method mentioned in the question. So what might be the problem? – ispiro Jan 01 '17 at 22:41
  • I mentioned [runtime permissions](https://developer.android.com/training/permissions/requesting.html) as being a possibility. – CommonsWare Jan 01 '17 at 22:42
  • I don't understand. As I've said in the question - I've already set that. – ispiro Jan 01 '17 at 22:45
  • 1
    "I've already set that" -- if by "set" you mean "you arranged to get it in the app's manifest", that is insufficient. "And I haven't been successful in trying to convert it to a Uri" -- in Java, that would be `Uri.fromFile(new File(something))`, where `something` is a `String` containing your `/storage/emulated/0/`-based value. That will not change your results, though. – CommonsWare Jan 01 '17 at 22:48
  • @CommonsWare Thanks! I didn't know either. That answers my question. – ispiro Jan 01 '17 at 22:52

2 Answers2

0

Visit android: Get real path from uri

You can get idea about how to get real path from this.

Community
  • 1
  • 1
Bhoomika Patel
  • 1,895
  • 1
  • 13
  • 30
0

Try to pass This instead of passing hardcoded value (/storage/emulated/0/)

String path= Environment.getExternalStorageDirectory()+"/yourFolder/";

Don't forget to add permission in manifest file

shivampip
  • 2,004
  • 19
  • 19