AMediaExtractor setDataSource AMEDIA_ERROR_UNSUPPORTED error on Android Q

无人久伴 提交于 2019-12-24 04:54:11

问题


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.

What I do

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;
    }

    .....
}

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

How to check this issue?


回答1:


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 .

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




回答2:


This is due to you not specifying a Java thread to be used. Create the thread and then attach it via AttachCurrentThread



来源:https://stackoverflow.com/questions/57653901/amediaextractor-setdatasource-amedia-error-unsupported-error-on-android-q

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!