0

I have a Mediametadatareview, but when I use setDataSource() gets out, I notice the error is due to a file with the name /storage/sdcard/NhạcCuảTôi.mp3 (The file name is Vietnamese). How to change that file to a true URI?

this is my code

 mediaMetadataRetriever = new MediaMetadataRetriever();       
 Uri u = Uri.parse(filedata);
 mediaMetadataRetriever.setDataSource(MainAC.this, u);
 String gene= mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE);

it crashed at mediaMetadataRetriever.setDataSource(MainAC.this, u);

I think the error is because the file name has an accent, is there any way to help convert the string to URI and unmark? Because if I delete the file with that sign then the application works normally

this is LOGCAT :

 java.lang.RuntimeException: Unable to start activity ComponentInfo{dragonrocky.music/dragonrocky.music.MainAC}: java.lang.RuntimeException: setDataSource failed: status = 0x80000000
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2505)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2577)
    at android.app.ActivityThread.access$1000(ActivityThread.java:164)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1462)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:160)
    at android.app.ActivityThread.main(ActivityThread.java:5541)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)
    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:107)
 Caused by: java.lang.RuntimeException: setDataSource failed: status = 0x80000000
    at android.media.MediaMetadataRetriever.setDataSource(Native Method)
    at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:71)
    at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:165)
    at dragonrocky.music.MainAC.loadAudio(MainAC.java:519)
    at dragonrocky.music.MainAC.onCreate(MainAC.java:156)
    at android.app.Activity.performCreate(Activity.java:6093)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2458)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2577) 
    at android.app.ActivityThread.access$1000(ActivityThread.java:164) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1462) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:160) 
    at android.app.ActivityThread.main(ActivityThread.java:5541) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759) 
    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:107) 

Thank You.

Diptendu Das
  • 3,990
  • 7
  • 22
  • 38
Binh Cao
  • 47
  • 1
  • 8

2 Answers2

0

Try this

Uri myUri = Uri.parse("/storage/sdcard/NhạcCuảTôi.mp3");
Diptendu Das
  • 3,990
  • 7
  • 22
  • 38
0

Do not use a Uri here. Either use the setDataSource(String) method and pass your path in directly, or open the file yourself and use setDataSource(FileDescriptor).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Use LogCat to examine your error: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Aug 01 '18 at 13:04
  • ok, i left LOGCAT above the post and i realized the problem is not in the filename because the previous filename also has the accent and it works normal – Binh Cao Aug 01 '18 at 13:10