在我的 public void onActivityResult(int requestCode, int resultCode, Intent data) {
......有这样的一部分:
if (requestCode == 1) {
// Make sure the request was successful
final Uri videoUri = data.getData();
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
//use one of overloaded setDataSource() functions to set your data source
retriever.setDataSource(getActivity(), videoUri);
String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
timeInMillisec = Long.parseLong(time );
retriever.release();
在这里,我试图获取视频持续时间MediaMetadataRetriever
并将其存储在 中timeInMillisec
,接下来我将检查timeInMillisec
任何错误的值:
Toast.makeText(getActivity(), (int) timeInMillisec, Toast.LENGTH_SHORT).show();
关键是,这里我有这个例外:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.zub.videoplay, PID: 9399
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=65537, result=-1, data=Intent { dat=content://com.miui.gallery.open/raw//storage/emulated/0/Download/Air Supply - All Out Of Love.mp4 typ=video/mp4 flg=0x1 }} to activity {com.example.zub.videoplay/com.example.zub.videoplay.HomeActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x37c3f
at android.app.ActivityThread.deliverResults(ActivityThread.java:4179)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4222)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1581)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6238)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x37c3f
at android.content.res.Resources.getText(Resources.java:351)
at android.content.res.MiuiResources.getText(MiuiResources.java:97)
at android.widget.Toast.makeText(Toast.java:285)
at com.example.zub.videoplay.onActivityResult(PostFragment.java:293)
at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:151)
at com.example.zub.videoplay.HomeActivity.onActivityResult(HomeActivity.java:586)
at android.app.Activity.dispatchActivityResult(Activity.java:7132)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4175)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4222)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1581)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6238)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
I/Process: Sending signal. PID: 9399 SIG: 9
我无法弄清楚这里出了什么问题。任何帮助将不胜感激。