Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/feat frank #13

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 31 additions & 30 deletions Android/Agora-RTC-QuickStart-Android/README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
# Agora-RTC-QuickStart

本示例介绍如何集成声网实时互动 SDK,通过少量代码从 0 开始实现一个简单的实时互动 App,适用于互动直播和视频通话场景。
*English | [中文](README.zh.md)*

## 前提条件
This example demonstrates how to integrate the Agora Real-Time Interactive SDK to create a simple real-time interactive app from scratch with minimal code, suitable for interactive live streaming and video calling scenarios.

在实现功能以前,请按照以下要求准备开发环境:
## Prerequisites

- Android Studio 4.1 以上版本。
- Android API 级别 16 或以上。
- 两台运行 Android 4.1 或以上版本的移动设备
- 可以访问互联网的计算机。如果你的网络环境部署了防火墙,参考[应对防火墙限制](https://doc.shengwang.cn/doc/rtc/android/basic-features/firewall)以正常使用声网服务。
- 一个有效的声网账号以及声网项目。请参考[开通服务](https://doc.shengwang.cn/doc/rtc/android/get-started/enable-service)从声网控制台获得以下信息:
- App ID:声网随机生成的字符串,用于识别你的项目。
- 临时 Token:Token 也称为动态密钥,在客户端加入频道时对用户鉴权。临时 Token 的有效期为 24 小时。
Before implementing the functionality, please prepare your development environment according to the following requirements:

## 运行示例程序
- Android Studio version 4.1 or above.
- Android API level 16 or above.
- Two mobile devices running Android 4.1 or above.
- A computer with internet access. If your network environment has a firewall, refer to Dealing with [Firewall Restrictions](https://docs.agora.io/en/video-calling/core-functionality/cloud-proxy?platform=android) to use Agora services normally.
- An active Agora account and an Agora project. Please refer to [Enabling Services](https://docs.agora.io/en/video-calling/get-started/manage-agora-account?platform=android) to obtain the following information from the Agora Console:
- App ID:A randomly generated string by Agora to identify your project.
- Temporary Token: Also known as a dynamic key, used for user authentication when joining a channel. The temporary token is valid for 24 hours.

这个段落主要讲解了如何编译和运行实例程序。
## Running the Sample Program

1. 进入到[后台](https://console.shengwang.cn/)项目里,复制后台的 **App Id** 并备注,稍后启动应用时会用到它
2. (可选)如果开启安全模式,则使用[临时 token 生成器](https://docportal.shengwang.cn/cn/Agora%20Platform/get_appid_token?platform=All%20Platforms#%E8%8E%B7%E5%8F%96%E4%B8%B4%E6%97%B6-token)生成一个频道的RTC产品临时token,复制**频道名**和 **Token** 并备注,稍后启动应用时会用到它
3. 编辑 `app/src/main/java/io/agora/quickstart/rtc/MainActivity.java`,将你的 AppID 、频道名、Token 分别替换到 `<#Your App ID#>` 、 `<#Your channel name#>`、`<#Your Token#>`
This section explains how to compile and run the sample program.

1. Go to the [Console project](https://console.agora.io/v2), copy the **App ID** from the backend, and make a note of it, as you will need it when launching the app later.
2. (Optional) If you enable security mode, use the [Temporary Token Generator](https://docs.agora.io/en/video-calling/get-started/manage-agora-account?platform=android#generate-temporary-tokens) to generate a temporary RTC token for a channel, and make a note of the **Channel Name** and **Token**, as you will need them when launching the app later.
3. Edit `app/src/main/java/io/agora/quickstart/rtc/MainActivity.java`, replacing `<#Your App ID#>`, `<#Your channel name#>`, and `<#Your Token#>` with your App ID, channel name, and token, respectively.

```
// 填写项目的 App ID,可在声网控制台中生成
// Enter the App ID for your project, which can be generated in the Agora Console
private String appId = "<#Your App ID#>";
// 填写频道名
// Enter the channel name
private String channelName = "<#Your channel name#>";
// 填写声网控制台中生成的临时 Token
// Enter the temporary Token generated in the Agora Console
private String token = "<#Your Token#>";
```
4. 使用Android Studio打开[Android/Agora-RTC-QuickStart-Android](.),等待下载依赖并同步成功
4.Open [Android/Agora-RTC-QuickStart-Android](.) in Android Studio and wait for the dependencies to download and sync successfully.

然后你就可以编译并运行项目了。
You can then compile and run the project.

## 联系我们
## Contact Us

- 如果你遇到了困难,可以先参阅 [常见问题](https://docportal.shengwang.cn/cn/Real-time-Messaging/faq)
- 如果你想了解更多官方示例,可以参考 [官方SDK示例](https://github.com/AgoraIO)
- 如果你想了解声网SDK在复杂场景下的应用,可以参考 [官方场景案例](https://github.com/AgoraIO-usecase)
- 如果你想了解声网的一些社区开发者维护的项目,可以查看 [社区](https://github.com/AgoraIO-Community)
- 完整的 API 文档见 [文档中心](https://docportal.shengwang.cn/cn)
- 若遇到问题需要开发者帮助,你可以到 [开发者社区](https://rtcdeveloper.com/) 提问
- 如果需要售后技术支持, 你可以在 [Agora Dashboard](https://dashboard.agora.io) 提交工单
- 如果发现了示例代码的 bug,欢迎提交 [issue](https://github.com/AgoraIO-Community/Agora-RTC-QuickStart/issues)
- For potential issues, take a look at our [FAQ](https://docs.agora.io/en/faq) first
- Dive into [Agora SDK Samples](https://github.com/AgoraIO) to see more tutorials
- Take a look at [Agora Use Case](https://github.com/AgoraIO-usecase) for more complicated real use case
- Repositories managed by developer communities can be found at [Agora Community](https://github.com/AgoraIO-Community)
- You can find full API documentation at [Document Center](https://docs.agora.io/en/)
- If you encounter problems during integration, you can ask question in [Stack Overflow](https://stackoverflow.com/questions/tagged/agora.io)
- You can file bugs about this sample at [issue](https://github.com/AgoraIO/API-Examples/issues)

## 代码许可
## License

The MIT License (MIT)
52 changes: 52 additions & 0 deletions Android/Agora-RTC-QuickStart-Android/README.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Agora-RTC-QuickStart

*[English](README.md) | 中文*

本示例介绍如何集成声网实时互动 SDK,通过少量代码从 0 开始实现一个简单的实时互动 App,适用于互动直播和视频通话场景。

## 前提条件

在实现功能以前,请按照以下要求准备开发环境:

- Android Studio 4.1 以上版本。
- Android API 级别 16 或以上。
- 两台运行 Android 4.1 或以上版本的移动设备
- 可以访问互联网的计算机。如果你的网络环境部署了防火墙,参考[应对防火墙限制](https://doc.shengwang.cn/doc/rtc/android/basic-features/firewall)以正常使用声网服务。
- 一个有效的声网账号以及声网项目。请参考[开通服务](https://doc.shengwang.cn/doc/rtc/android/get-started/enable-service)从声网控制台获得以下信息:
- App ID:声网随机生成的字符串,用于识别你的项目。
- 临时 Token:Token 也称为动态密钥,在客户端加入频道时对用户鉴权。临时 Token 的有效期为 24 小时。

## 运行示例程序

这个段落主要讲解了如何编译和运行实例程序。

1. 进入到[后台](https://console.shengwang.cn/)项目里,复制后台的 **App Id** 并备注,稍后启动应用时会用到它
2. (可选)如果开启安全模式,则使用[临时 token 生成器](https://docportal.shengwang.cn/cn/Agora%20Platform/get_appid_token?platform=All%20Platforms#%E8%8E%B7%E5%8F%96%E4%B8%B4%E6%97%B6-token)生成一个频道的RTC产品临时token,复制**频道名**和 **Token** 并备注,稍后启动应用时会用到它
3. 编辑 `app/src/main/java/io/agora/quickstart/rtc/MainActivity.java`,将你的 AppID 、频道名、Token 分别替换到 `<#Your App ID#>` 、 `<#Your channel name#>`、`<#Your Token#>`

```
// 填写项目的 App ID,可在声网控制台中生成
private String appId = "<#Your App ID#>";
// 填写频道名
private String channelName = "<#Your channel name#>";
// 填写声网控制台中生成的临时 Token
private String token = "<#Your Token#>";
```
4. 使用Android Studio打开[Android/Agora-RTC-QuickStart-Android](.),等待下载依赖并同步成功

然后你就可以编译并运行项目了。

## 联系我们

- 如果你遇到了困难,可以先参阅 [常见问题](https://docportal.shengwang.cn/cn/Real-time-Messaging/faq)
- 如果你想了解更多官方示例,可以参考 [官方SDK示例](https://github.com/AgoraIO)
- 如果你想了解声网SDK在复杂场景下的应用,可以参考 [官方场景案例](https://github.com/AgoraIO-usecase)
- 如果你想了解声网的一些社区开发者维护的项目,可以查看 [社区](https://github.com/AgoraIO-Community)
- 完整的 API 文档见 [文档中心](https://docportal.shengwang.cn/cn)
- 若遇到问题需要开发者帮助,你可以到 [开发者社区](https://rtcdeveloper.com/) 提问
- 如果需要售后技术支持, 你可以在 [Agora Dashboard](https://dashboard.agora.io) 提交工单
- 如果发现了示例代码的 bug,欢迎提交 [issue](https://github.com/AgoraIO-Community/Agora-RTC-QuickStart/issues)

## 代码许可

The MIT License (MIT)
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
public class MainActivity extends AppCompatActivity {

// 填写项目的 App ID,可在声网控制台中生成
// Enter the App ID for your project, which can be generated in the Agora Console
private String appId = "<#Your App ID#>";
// 填写频道名
// Enter the channel name
private String channelName = "<#Your channel name#>";
// 填写声网控制台中生成的临时 Token
// Enter the temporary Token generated in the Agora Console
private String token = "<#Your Token#>";


Expand All @@ -42,9 +45,11 @@ public void onJoinChannelSuccess(String channel, int uid, int elapsed) {

@Override
// 监听频道内的远端用户,获取用户的 uid 信息
//Listen to remote users in the channel and retrieve their UID information.
public void onUserJoined(int uid, int elapsed) {
runOnUiThread(() -> {
// 获取 uid 后,设置远端视频视图
// After obtaining the UID, set the remote video view.
setupRemoteVideo(uid);
});
}
Expand All @@ -61,38 +66,48 @@ public void onUserOffline(int uid, int reason) {
private void initializeAndJoinChannel() {
try {
// 创建 RtcEngineConfig 对象,并进行配置
// Create and configure the RtcEngineConfig object
RtcEngineConfig config = new RtcEngineConfig();
config.mContext = getBaseContext();
config.mAppId = appId;
config.mEventHandler = mRtcEventHandler;
// 创建并初始化 RtcEngine
// Create and initialize the RtcEngine
mRtcEngine = RtcEngine.create(config);
} catch (Exception e) {
throw new RuntimeException("Check the error.");
}
// 启用视频模块
// Enable the video module.
mRtcEngine.enableVideo();

// 创建一个 SurfaceView 对象,并将其作为 FrameLayout 的子对象
// Create a SurfaceView object and add it as a child to the FrameLayout
FrameLayout container = findViewById(R.id.local_video_view_container);
SurfaceView surfaceView = new SurfaceView (getBaseContext());
container.addView(surfaceView);
// 将 SurfaceView 对象传入声网实时互动 SDK,设置本地视图
// Pass the SurfaceView object to the Agora Real-Time Interactive SDK to set the local view.
mRtcEngine.setupLocalVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT, 0));
// 开启本地预览
// Start local preview
mRtcEngine.startPreview();

// 创建 ChannelMediaOptions 对象,并进行配置
// Create and configure the ChannelMediaOptions object
ChannelMediaOptions options = new ChannelMediaOptions();
// 根据场景将用户角色设置为 BROADCASTER (主播) 或 AUDIENCE (观众)
// Set the user role as BROADCASTER (host) or AUDIENCE (audience) based on the scenario
options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER;
// 直播场景下,设置频道场景为 BROADCASTING (直播场景)
// In the live broadcast scenario, set the channel profile as BROADCASTING
options.channelProfile = Constants.CHANNEL_PROFILE_LIVE_BROADCASTING;
options.publishMicrophoneTrack = true;
options.publishCameraTrack = true;
options.autoSubscribeAudio = true;
options.autoSubscribeVideo = true;
// 使用临时 Token 加入频道,自行指定用户 ID 并确保其在频道内的唯一性
// Join the channel with a temporary Token, specify the user ID, and ensure that it is unique in the channel
mRtcEngine.joinChannel(token, channelName, 0, options);
}

Expand All @@ -102,20 +117,23 @@ private void setupRemoteVideo(int uid) {
surfaceView.setZOrderMediaOverlay(true);
container.addView(surfaceView);
// 将 SurfaceView 对象传入声网实时互动 SDK,设置远端视图
//Pass the SurfaceView object to the Agora Real-Time Interaction SDK to set up the remote view.
mRtcEngine.setupRemoteVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT, uid));
}

private static final int PERMISSION_REQ_ID = 22;

// 获取体验实时音视频互动所需的录音、摄像头等权限
// Get the permissions required for real-time audio and video interaction
private String[] getRequiredPermissions(){
// 判断 targetSDKVersion 31 及以上时所需的权限
// Determine the permissions required when targetSDKVersion is 31 or higher
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
return new String[]{
Manifest.permission.RECORD_AUDIO, // 录音权限
Manifest.permission.CAMERA, // 摄像头权限
Manifest.permission.READ_PHONE_STATE, // 读取电话状态权限
Manifest.permission.BLUETOOTH_CONNECT // 蓝牙连接权限
Manifest.permission.RECORD_AUDIO, // 录音权限 // Recording permission
Manifest.permission.CAMERA, // 摄像头权限 // Camera permission
Manifest.permission.READ_PHONE_STATE, // 读取电话状态权限 // Read phone state permission
Manifest.permission.BLUETOOTH_CONNECT // 蓝牙连接权限 // Bluetooth connection permission
};
} else {
return new String[]{
Expand All @@ -140,6 +158,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 如果已经授权,则初始化 RtcEngine 并加入频道
//If authorization has been granted, initialize the RtcEngine and join the channel.
if (checkPermissions()) {
initializeAndJoinChannel();
} else {
Expand All @@ -151,6 +170,7 @@ protected void onCreate(Bundle savedInstanceState) {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
// 系统权限申请回调
// System permission request callback
if (checkPermissions()) {
initializeAndJoinChannel();
}
Expand All @@ -161,9 +181,11 @@ protected void onDestroy() {
super.onDestroy();

// 停止本地视频预览
// Stop local video preview
mRtcEngine.stopPreview();

// 离开频道
// Leave the channel
mRtcEngine.leaveChannel();

RtcEngine.destroy();
Expand Down
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# Agora QuickStart

_English | [中文](README.zh.md)

## 简介
## Overview

此仓库包含 Agora RTC Native SDK 的QuickStart示例项目。
This repository contains QuickStart example projects for the Agora RTC Native SDK.

| 平台 | 语言 | 项目位置 | SDK |
| Platform | Language | Project Location | SDK |
| -------- | -------- |------------------------------------------------------| ------------------------------------------------------------------------------------------------------------------------------- |
| Android | Java | [Agora-RTC-QuickStart](Android/Agora-RTC-QuickStart-Android) | [RTC Java Video SDK](https://doc.shengwang.cn/doc/rtc/android/resources) |
| iOS | Swift | [Agora-RTC-QuickStart](iOS/Agora-RTC-QuickStart-iOS) | [RTC Swift Video SDK](https://doc.shengwang.cn/doc/rtc/ios/resources) |
| Android | Java | [Agora-RTC-QuickStart](Android/Agora-RTC-QuickStart-Android) | [RTC Java Video SDK](https://docs.agora.io/en/sdks?platform=android) |
| iOS | Swift | [Agora-RTC-QuickStart](iOS/Agora-RTC-QuickStart-iOS) | [RTC Swift Video SDK](https://docs.agora.io/en/sdks?platform=ios) |

你可以进入不同平台的项目进行试用或参考源代码。
You can access projects on different platforms for trial or to reference the source code.

## 反馈
## Feedback

如果你有任何问题或建议,可以通过 issue 的形式反馈。
If you have any problems or suggestions regarding the sample projects, feel free to file an issue.

## 相关资源
## Related resources

- 你可以先参阅 [常见问题](https://docportal.shengwang.cn/cn/Real-time-Messaging/faq)
- 如果你想了解更多官方示例,可以参考 [官方 SDK 示例](https://github.com/AgoraIO)
- 如果你想了解声网 SDK 在复杂场景下的应用,可以参考 [官方场景案例](https://github.com/AgoraIO-usecase)
- 如果你想了解声网的一些社区开发者维护的项目,可以查看 [社区](https://github.com/AgoraIO-Community)
- 若遇到问题需要开发者帮助,你可以到 [开发者社区](https://rtcdeveloper.com/) 提问
- 如果需要售后技术支持, 你可以在 [Agora Dashboard](https://dashboard.agora.io) 提交工单
- Check our [FAQ](https://docs.agora.io/en/faq) to see if your issue has been recorded.
- Dive into [Agora SDK Samples](https://github.com/AgoraIO) to see more tutorials.
- Take a look at [Agora Use Case](https://github.com/AgoraIO-usecase) for more complicated real use case.
- Repositories managed by developer communities can be found at [Agora Community](https://github.com/AgoraIO-Community).
- If you encounter problems during integration, feel free to ask questions in [Stack Overflow](https://stackoverflow.com/questions/tagged/agora.io).

## 许可证
## License

示例项目遵守 MIT 许可证。
The sample projects are under the MIT license.
Loading