构建 TV 播放应用
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
TV 应用提供的用户体验常常包含媒体文件浏览和播放。从头开始构建这种体验,同时还要确保体验速度快、流畅且有吸引力,可能具有相当大的挑战性。无论您的应用提供对小型还是大型媒体目录的访问,都必须让用户能够快速浏览他们选择的内容并找到需要的内容。
主题
- 使用 Compose for TV 构建界面
注意:使用视图和 fragment 的 Leanback 界面工具包已废弃,取而代之的是 Compose。
- 实现媒体会话
- 使用
MediaSession
告知 Android TV 您的应用中正在播放的内容,并允许来自应用外部的互动控制媒体。
- 电视上的播放控件
- 在 Android TV OS 上打造一致的播放体验的最佳实践。
- 显示“正在播放”卡片
- 使用
MediaSession
在主屏幕上显示“正在播放”卡片。
- 显示视频预览
- 直接在主屏幕的 Surface 上呈现预览视频。
- 支持氛围模式
- 节省电量并避免屏幕烧屏问题。
- 匹配内容帧速率
- 使用帧速率 API 管理帧速率。
- 优化内存用量
- 优化应用的内存用量。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Build TV playback apps\n\nBrowsing and playing media files is frequently part of the user experience provided by a TV app.\nBuilding such an experience from scratch while making sure that it is fast, fluid, and attractive\ncan be challenging. Whether your app provides access to a small or large media catalog,\nenable users to quickly browse options and get to the content they want.\n\nTopics\n------\n\n**Build UIs with Compose for TV**\n**[Implement a media session](/training/tv/playback/media-session)**\n: Use a `MediaSession` to inform Android TV what's playing in your app and let\n interactions from outside your app control media.\n\n**[Playback controls on TV](/training/tv/playback/controls)**\n: Best practices for creating a consistent playback experience across Android TV\n OS.\n\n**[Display a Now Playing card](/training/tv/playback/now-playing)**\n: Use a `MediaSession` to display a Now Playing card on the home\n screen.\n\n**[Display video previews](../discovery/preview-videos)**\n: Render a preview video directly on a surface of the\n [home screen](/training/tv/discovery/recommendations-channel).\n\n**[Support Ambient Mode](/training/tv/playback/ambient-mode)**\n: Save energy and avoid screen burn issues.\n\n**[Match content frame rate](/training/tv/playback/framerate)**\n: Manage frame rates using the frame rate API.\n\n**[Optimize memory usage](/training/tv/playback/memory)**\n: Optimize memory usage for your app."]]