媒体应用可能需要大量资源,包括内存、CPU、网络连接和硬件编解码器,其中许多资源短缺。此外,应用还必须可靠地管理与其他应用的交互,例如控制器应用发送播放命令请求或在系统中的其他位置启动媒体播放。本部分将介绍一些最佳实践,用于确保用户能够依赖您的应用获得良好性能且按预期运行。
性能和可靠性方面的最佳实践
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[],[],null,["# Best practices for performance and reliability\n\nMedia apps can demand a lot of resources including memory, CPU, network\nconnections and hardware codecs, many of which are in short supply.\nIn addition, apps have to reliably manage interacting with other apps, such as\ncontroller apps sending playback command requests or media playback starting\nelsewhere in the system. This section discusses best practices for making sure\nthat users can rely on your app to perform well and as expected.\n\n- Use testing tools like the [Media Controller Test app](/media/optimize/mct) to validate your playback use-cases\n- Use a device's [performance class](/topic/performance/performance-class) level to accurately gauge device capabilities\n- Cooperate with other apps to [manage audio focus](/media/optimize/audio-focus)\n- [Measure](/media/optimize/performance/measure) your app's performance and make decisions accordingly\n- Maintain high quality when preparing to [share videos](/media/optimize/sharing)"]]