【问题标题】:MediaMetadataRetriever giving RunTimeExceptionMediaMetadataRetriever 给出 RunTimeException
【发布时间】:2019-07-20 05:25:12
【问题描述】:

在我的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

我无法弄清楚这里有什么问题。任何帮助将不胜感激。

【问题讨论】:

    标签: android runtimeexception mediametadataretriever


    【解决方案1】:

    这是堆栈跟踪的重要部分:

    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)
    

    看起来在HomeActivity.onActivityResult 中,您正试图通过Toast 显示一个不存在的字符串(ID #0x37c3f)。

    【讨论】:

    • 那我该怎么办呢?
    • 找到你想在哪里展示 toast(在 HomeActivity 中),看看你传入的是什么字符串。
    猜你喜欢
    • 1970-01-01
    • 2018-12-14
    • 2015-02-18
    • 1970-01-01
    • 2019-03-29
    • 2018-07-11
    • 1970-01-01
    • 1970-01-01
    • 2015-01-25
    相关资源
    最近更新 更多