[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# Customize media components\n\nYou can extend the media extractor and media codec components using vendor\nextensions. The MediaSession2 and MediaParser APIs can't be customized (but you\ncan upstream changes for the legacy `MediaPlayer` and `MediaSession` APIs).\n\nTo support additional media types in the Android media framework, you need to\ncreate a custom [extractor](#extractor) and [decoder](#decoder). For example,\nto add support for Windows Media video in AVI files, you need to create an AVI\n[Extractor](#extractor) and a Windows Media video [Decoder](#decoder).\n\nAbout extensions\n----------------\n\nIf the default media extractors don't meet your requirements, you can place\ncustom extractor plugins in `/system/lib[64]/extractors/`. The extractor process\nautomatically loads extractor plugins from the Google-provided APEX package and\nfrom `/system/lib[64]/extractors/`.\n\nSimilarly, you can set up custom media codec services that use the Codec 2.0\ninterface defined in `frameworks/av/media/codec2/core/`. For a basic\nimplementation, refer to `frameworks/av/media/codec2/hidl/services/`. The\nlibrary entry point is the `C2ComponentStore` interface. For an example, refer\nto the default software codec store implementation at\n`frameworks/av/media/codec2/vndk/C2Store.cpp`.\n\nWhen using your own APEX, structure the codec service and load the APEX file\nusing the same processes as the `mediaswcodec` service. To do so, define a\ntop-level shared library responsible for registering all C2 components, then\ncreate an APEX package (with transitive dependencies) that resides in the vendor\npartition. When the vendor codec service process starts, it can then load this\ntop-level entry point.\n\nCreate an extractor\n-------------------\n\n| **Note:** Before adding a custom extractor, consider extending an existing extractor and upstreaming your changes to make them part of the platform (and reduce maintenance).\n\nWhen adding an extractor for a new format, ensure the extractor depends only on\nstable NDK APIs and doesn't depend on any private APIs. Extractors should\nimplement the API defined by\n`frameworks/av/include/media/MediaExtractorPluginApi.h` and can use the C++\nconvenience wrappers in\n`frameworks/av/include/media/MediaExtractorPluginHelper.h`. Because Android\n10 or higher supports only the highest version of the\nextractor API, be sure to model your extractor after the extractor with the\nhighest API version number.\n\nPlace custom extractors in `/system/lib/64/extractors` or a vendor APEX,\nwhich is opened along with the Google APEX containing the Google extractors. To\nverify the framework loaded your extractor, run the following command. \n\n adb shell dumpsys media.extractor\n\nYou should get a list of available extractors that is similar to the following. \n\n Available extractors:\n AAC Extractor: plugin\\_version(2), uuid(4fd80eae03d24d729eb948fa6bb54613), version(1), path(/system/lib64/extractors/libaacextractor.so)\n AMR Extractor: plugin\\_version(2), uuid(c86639c92f3140aca715fa01b4493aaf), version(1), path(/system/lib64/extractors/libamrextractor.so)\n FLAC Extractor: plugin\\_version(2), uuid(1364b048cc454fda9934327d0ebf9829), version(1), path(/system/lib64/extractors/libflacextractor.so)\n MIDI Extractor: plugin\\_version(2), uuid(ef6cca0af8a243e6ba5fdfcd7c9a7ef2), version(1), path(/system/lib64/extractors/libmidiextractor.so)\n MP3 Extractor: plugin\\_version(2), uuid(812a3f6cc8cf46deb5293774b14103d4), version(1), path(/system/lib64/extractors/libmp3extractor.so)\n MP4 Extractor: plugin\\_version(2), uuid(27575c6744174c548d3d8e626985a164), version(2), path(/system/lib64/extractors/libmp4extractor.so)\n MPEG2-PS/TS Extractor: plugin\\_version(1), uuid(3d1dcfebe40a436da574c2438a555e5f), version(1), path(/system/lib64/extractors/libmpeg2extractor.so)\n Matroska Extractor: plugin\\_version(2), uuid(abbedd9238c44904a4c1b3f45f899980), version(1), path(/system/lib64/extractors/libmkvextractor.so)\n Ogg Extractor: plugin\\_version(2), uuid(8cc5cd06f772495e8a62cba9649374e9), version(1), path(/system/lib64/extractors/liboggextractor.so)\n WAV Extractor: plugin\\_version(3), uuid(7d61385858374a3884c5332d1cddee27), version(1), path(/system/lib64/extractors/libwavextractor.so)\n\nIf your custom extractor supports a format that is already supported by a\nGoogle-provided extractor, you can force the framework to use your extractor by\nusing the `Sniff()` function to return a higher confidence level than the\nGoogle-provided one.\n\nWhen the media framework loads your extractor (from `/system/lib/64/extractors`\nor from a vendor APEX), it recognizes the file and gets information about its\ncontent. The next step is to add a decoder for the format so the framework can\nunderstand how to parse the file content.\n\nCreate a custom decoder\n-----------------------\n\nYou need a custom decoder for any format that isn't already supported by a\nGoogle-provided decoder. For example:\n\n- To add media framework support for AVI files containing MP3, you need an AVI\n extractor but don't need a MP3 decoder because one already exists.\n\n- To add media framework support for AVI files containing Windows Media, you\n need both an AVI extractor and a Windows Media decoder.\n\nAdding a new decoder is similar to adding your own hardware decoders for AVC or\nHEVC.\n\nWhile the extractor publishes the MIME type of the media tracks that it\ncontains, the codecs that support these MIME types need to be present for the\nfile to be fully supported. The actual MIME type string used is strictly an\nagreement between the extractor and the codec (the string doesn't need to be\nadded to the `MediaDefs.h` file).\n\nIntegrate with media scanner\n----------------------------\n\nThe media scanner looks for new file types and adds them to the media database.\nTo have the media scanner handle your custom file type, the scanner needs to\nknow about it. In Android 10 or higher, `MimeUtils` (in\n`libcore`) maintains the MIME-to-extension mapping. Previously, this mapping was\nhandled in the `MediaFile.java` file, which continues to contain a mapping from\nMIME type to MTP format constants.\n\nAn extractor can export a list of filename extensions they support (such as MP3\nor MP4). However, only `LegacyMediaScanner` uses that; it has no effect on\n`ModernMediaScanner`, which used by default."]]