Android 游戏中的视频录制功能
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在弃用 Google 登录 API 后,我们将于 2026 年移除 games v1 SDK。2025 年 2 月之后,您将无法在 Google Play 上发布新集成了 games v1 SDK 的游戏。我们建议您改用 games v2 SDK。
虽然采用旧版游戏 v1 集成的现有游戏仍可在未来几年内正常运行,但我们建议您从 2025 年 6 月开始迁移到 v2。
本指南介绍了如何使用 Play 游戏服务 v1 SDK。Play 游戏服务 v2 SDK 不支持视频录制。
借助 Video Recording API,您可以轻松地为游戏添加视频录制功能,并让用户只需几个简单的步骤即可在 YouTube 上与好友分享视频。例如,您可以在战斗重玩屏幕上添加一个按钮,当用户按下该按钮时,系统会显示 Play 游戏视频录制体验。
本指南介绍了如何使用 Google Play 游戏服务在游戏中实现视频录制功能。这些 API 可在 com.google.android.gms.games.video
和 com.google.android.gms.games
软件包中找到。
准备工作
在开始使用 Video Recording API 之前,请执行以下操作:
获取视频客户端
如需开始使用视频录制 API,您的游戏必须先获取一个 VideosClient
对象。为此,您可以调用 Games.getVideosClient()
方法,并传入 activity 和当前播放器的 GoogleSignInAccount
。如需了解如何检索玩家的账号信息,请参阅 Android 游戏中的登录功能。
Video Recording API 基础知识
您可以使用视频录制 API 直接在游戏中集成视频录制体验。
用户的视频录制体验包括以下内容:
启动视频录制叠加层
如需为当前已登录的玩家启动视频录制,请按以下步骤操作:
- 调用
VideosClient.getCaptureOverlayIntent()
方法。
- 如果调用成功,Google Play 游戏服务会返回一个
Task
对象,用于异步加载 intent 以启动视频录制叠加层。
- 使用上一步中的 intent 启动 activity。
以下示例展示了如何调出视频录制叠加层:
private static final int RC_VIDEO_OVERLAY = 9011;
public void showVideoOverlay(View myview) {
Games.getVideosClient(this, GoogleSignIn.getLastSignedInAccount(this))
.getCaptureOverlayIntent()
.addOnSuccessListener(new OnSuccessListener<Intent>() {
@Override
public void onSuccess(Intent intent) {
startActivityForResult(intent, RC_VIDEO_OVERLAY);
}
});
}
有关使用视频录制数据的提示
借助视频录制 API,您可以直接在游戏中集成视频录制体验。
提示 |
说明 |
让视频录制触发器易于发现 |
- 在主菜单中醒目地放置录制按钮
- 通过带有明确标签的专用录制模式菜单选项自动触发叠加层
|
在商品详情和游戏内宣传该功能的使用 |
- 在商品详情中使用显示视频录制叠加层的屏幕截图
- 通过游戏内促销宣传视频录制功能
- 考虑提供游戏内奖励来鼓励玩家分享重玩内容
|
通过回放比赛吸引玩家社区互动 |
- 通过每周 / 每月 / 每年的回放比赛,鼓励玩家录制和分享游戏回放
- 在游戏内或通过社交媒体发现热门视频和创作者
|
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Video recording in Android games\n\nFollowing the deprecation of the\n[Google Sign-In](https://android-developers.googleblog.com/2024/09/streamlining-android-authentication-credential-manager-replaces-legacy-apis.html)\nAPI, we are removing the games v1 SDK in 2026. After February 2025, you will be unable to publish\ntitles that are newly integrated with games v1 SDK, on Google Play. We recommend that you use the\ngames v2 SDK instead. \n\nWhile existing titles with the previous games v1 integrations continue to function for a\ncouple of years, you are encouraged to\n[migrate to v2](/games/pgs/android/migrate-to-v2)\nstarting June 2025. \n\nThis guide is for using the Play Games Services v1 SDK. Video recording\nis not supported in the Play Games Services v2 SDK.\n\nThe video recording API enables you to easily add video recording to your game\nand let users share their videos with friends on YouTube in a few simple\nsteps. For example, you could add a button off of a battle replay screen that\nwhen pressed would bring up the Play Games video recording experience.\n\nThis guide shows you how to implement video recording in games using the\nGoogle Play Games Services. The APIs can be found in the\n[`com.google.android.gms.games.video`](https://developers.google.com/android/reference/com/google/android/gms/games/video/package-summary) and\n[`com.google.android.gms.games`](https://developers.google.com/android/reference/com/google/android/gms/games/package-summary) packages.\n\nBefore you begin\n----------------\n\nBefore you start to use the video recording API:\n\n- Download and review the\n [code sample](https://github.com/playgameservices/android-basic-samples).\n\n- Familiarize yourself with the recommendations described in the\n [Quality Checklist](/games/pgs/v1/quality).\n\nGet the videos client\n---------------------\n\nTo start using the video recording API, your game must first obtain a\n[`VideosClient`](https://developers.google.com/android/games_v1/reference/com/google/android/gms/games/VideosClient.html) object. You can do this by calling the\n[`Games.getVideosClient()`](https://developers.google.com/android/reference/com/google/android/gms/games/Games.html#getVideosClient(android.app.Activity,%20com.google.android.gms.auth.api.signin.GoogleSignInAccount)) method and passing in the\nactivity and the [`GoogleSignInAccount`](https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInAccount) for the current player. To learn how to\nretrieve the player account information, see\n[Sign-in in Android Games](/games/pgs/v1/android/signin).\n| **Note:** The [`VideosClient`](https://developers.google.com/android/games_v1/reference/com/google/android/gms/games/VideosClient.html) class makes use of the Google Play services [`Task`](https://developers.google.com/android/reference/com/google/android/gms/tasks/Task) class to return results asynchronously. To learn more about using tasks to manage threaded work, see the [Tasks API developer guide](https://developers.google.com/android/guides/tasks).\n\nVideo recording API basics\n--------------------------\n\nYou can use the video recording API to integrate a video recording experience\ndirectly from within your game.\n\nThe video recording experience for users includes the following:\n\n- The video recording overlay, which has three buttons:\n\n 1. Start / stop recording\n 2. Turn on / off mic\n 3. Turn on / off forward facing camera\n\n | **Note:** Clicking the overlay's forward facing camera display brings up the three aforementioned buttons.\n- A developer-provided button to initiate recording, or an alternate recording\n trigger\n\n- A clickable toast that pops up at the end of recording that enables players to\n upload the video to YouTube, or view the video through the Photos app\n (Note: recorded videos are stored under the category `ScreenCasts` in Photos)\n\nLaunch the video recording overlay\n----------------------------------\n\nTo initiate video recording for the currently signed-in player, follow these\nsteps:\n\n1. Call the [`VideosClient.getCaptureOverlayIntent()`](https://developers.google.com/android/reference/com/google/android/gms/games/VideosClient.html#getCaptureOverlayIntent()) method.\n2. If the call is successful, Google Play games services returns a [`Task`](https://developers.google.com/android/reference/com/google/android/gms/tasks/Task) object which asynchronously loads an intent to launch the video recording overlay.\n3. Use the intent from the previous step to start an activity.\n\nHere's an example of how to bring up the video recording overlay: \n\n```transact-sql\nprivate static final int RC_VIDEO_OVERLAY = 9011;\n\npublic void showVideoOverlay(View myview) {\n Games.getVideosClient(this, GoogleSignIn.getLastSignedInAccount(this))\n .getCaptureOverlayIntent()\n .addOnSuccessListener(new OnSuccessListener\u003cIntent\u003e() {\n @Override\n public void onSuccess(Intent intent) {\n startActivityForResult(intent, RC_VIDEO_OVERLAY);\n }\n });\n}\n```\n\nTips for using video recording data\n-----------------------------------\n\nThe video recording API lets you integrate a video recording experience directly\nin your game.\n\n| Tip | Description |\n|----------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Make the video recording trigger easily discoverable | - Prominently place a recording button off your main menu - Automatically trigger the overlay from a dedicated and clearly labeled recording mode menu option |\n| Promote use of the feature in your store listing and inside the game | - Use a screenshot in your store listing that displays the video recording overlay - Promote the video recording feature through in-game promotions - Consider providing in-game rewards for replay sharing |\n| Engage your player community with replay competitions | - Encourage players to record and share game replays with weekly / monthly / yearly replay competitions - Recognize top videos and creators in-game or through social media |"]]