Android Q上的AMediaExtractor setDataSource AMEDIA_ERROR_UNSUPPORTED错误 [英] AMediaExtractor setDataSource AMEDIA_ERROR_UNSUPPORTED error on Android Q

查看:603
本文介绍了Android Q上的AMediaExtractor setDataSource AMEDIA_ERROR_UNSUPPORTED错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AMediaCodecAMediaExtractor,在所有设备上都可以正常工作(我希望:),但是如果我在Android Q上检查相同的代码(在我的情况下为Pixel 2XL),则会出现此错误.

I am working with AMediaCodec and AMediaExtractor, all works fine on all devices(I hope:), but if I check the same code on Android Q (in my case Pixel 2XL) I got such error AMEDIA_ERROR_UNSUPPORTED.

我做什么

bool NativeCodec::createStreamingMediaPlayer(const std::string &filename)
{
    AMediaExtractor *ex = AMediaExtractor_new();
    media_status_t err = 
      AMediaExtractor_setDataSource(ex, filename.c_str());;  <-- Here media status I got AMEDIA_ERROR_UNSUPPORTED 

    if (err != AMEDIA_OK)
    {
        __android_log_print(ANDROID_LOG_ERROR, "ERROR", "ERROR ::: %s", std::to_string(err).c_str());
        return false;
    }

    .....
}

也许这与Android Q中引入的私有性有某种联系,但是我没有找到有关它的任何信息...

Maybe this is somehow connected with privicy that was introduced in Android Q, but I didn't find any info about it...

如何检查此问题?

推荐答案

在我看来,这似乎是Android 10上的一个错误.您可能必须在清单上请求<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE/>并在运行时请求相同的许可. AMediaExtractor_setDataSource函数必须在连接到Java的线程上调用.正确执行所有操作后,您可以使其在其他版本的Android上运行,但不能在Android 10上运行.我在以下位置的Android Bug Tracker上报告了该问题: https://www.youtube.com/watch?v=UnJ3amzJM94 .

This to me seems a bug on Android 10. It seems that android:requestLegacyExternalStorage="true" does not change the situation. You may have to request <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE/> on manifest and ask same permission at runtime. The AMediaExtractor_setDataSource function must be called on a thread that is attached to Java. Doing all of that correctly will allow you to make it work on other versions of Android but not on Android 10. I've reported the issue on Android Bug Tracker here: https://issuetracker.google.com/144837266 As per google answer, it seems that all the app using native libraries that require file access through path can be affected and they know the issue https://www.youtube.com/watch?v=UnJ3amzJM94 .

在我的情况下,一种解决方法是使用AMediaExtractor_setDataSourceFd,通过contentResolver及其方法openFileDescriptor在Java级别获取文件描述符.

A workaround in my case was to use AMediaExtractor_setDataSourceFd, getting the file descriptor at Java level through contentResolver and its method openFileDescriptor.

这篇关于Android Q上的AMediaExtractor setDataSource AMEDIA_ERROR_UNSUPPORTED错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆