1 Star 0 Fork 0

Aegis / Online-KTV

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Online KTV(一起 KTV)

Other language: English

场景描述

“一起KTV” 是一个依附于直播聊天室的娱乐场景。在这个场景中,一个KTV房间里的演唱者给其他人播放 MV 视频,并跟随 MV 唱歌给所有人听。其中:

  1. 观众可以上麦,随时与房主进行实时音视频互动;
  2. 演唱者随着 MV 唱歌时,可以控制歌曲的切换和暂停;
  3. 演唱者也可以单独只播放 MV 文件;
  4. 演唱者可以自己调节 MV 伴奏和人声的音量;
  5. 观众可以排麦,当前演唱者结束后由下一位排麦中的人成为演唱者;

其中需要的功能有:

  1. 基础的音视频互动直播,包括主播、互动连麦;
  2. 本地/在线 MV 文件读取;
  3. 将 MV 伴奏和视频发送给其他人;
  4. 演唱者人声和 MV 伴奏音乐的混合;

架构设计

声网的“一起KTV”场景方案,提供了这个场景中实时音视频互动直播、MV 文件读取、人声和 MV 伴奏同步、音量控制、播放控制、发送 MV 伴奏和视频数据 等相关功能的解决方案。

整体架构如下图所示:

  1. 演唱者和其他用户一起加入声网频道,实现实时音视频通话,其中当前演唱者和连麦者为主播模式,听众为观众模式;
  2. 演唱者播放本地或者在线的 MV 文件;
  3. MV 文件解码出来的音频帧数据,混音进声网 SDK 采集到的演唱者歌声,并通过声网 SDK 发送到频道中;
  4. MV 文件解码出来的视频帧数据通过声网 SDK 发送到频道中;
  5. 房间内的其他用户通过声网 SDK 接收演唱者的歌声和 MV 数据。

运行示例 Demo

  1. Agora.io 用户注册页 注册账号,并创建自己的项目获取到 App ID。

  2. 下载 Agora 视频通话/视频直播 SDK

Android

  1. 将有效的 App ID 填写进本项目的 Agora-Online-KTV/app/src/main/res/values/strings_config.xml 中。

    <string name="agora_app_id"><#YOUR APP ID#></string>
  2. 解压下载到的 SDK 包,将其中的 libs 文件夹下的 *.jar 复制到本项目的 Android/Agora-Online-KTV/app/libs 下,其中的 libs 文件夹下的 arm64-v8a/x86/armeabi-v7a 复制到本项目的 Android/Agora-Online-KTV/app/src/main/jniLibs

  3. 使用 Android Studio 打开该项目,连接 Android 测试设备,编译并运行。

运行环境:
* Android SDK API Level >= 16
* Android Studio 3.1 +
* Android 4.1 或以上支持语音和视频功能的真机设备

iOS

  1. 将有效的 App ID 填写进 AgoraVideoViewController.m 中。

    self.rtcEngine = [AgoraRtcEngineKit sharedEngineWithAppId:<#APP_ID#> delegate:self];
  2. 解压下载到的 SDK 包,将其中的 AgoraRtcEngineKit.framework 复制到本项目的 Agora-Online-KTV/Agora-Online-KTV 目录下。

  3. 使用 Xcode 打开 Agora-Online-KTV/Agora-Online-KTV.xcodeproj,连接 iOS 测试设备,设置有效的开发者签名后即可运行。

运行环境:
​* Xcode 10.0 +
​* iOS 8.0 +

API 列表

示例 App 的 API 流程如下图所示。其中 KTVKit 模块已经封装了在 KTV 场景下的声网引擎和 IJKPlayer 相关功能。

Agora SDK 关键 API 列表:

iOS Android
sharedEngineWithAppId:delegate: create
setChannelProfile setChannelProfile
setClientRole setClientRole
enableVideo enableVideo
setAudioProfile setAudioProfile
joinChannel joinChannel
onRecordAudioFrame onRecordAudioFrame
onPlaybackAudioFrame onPlaybackAudioFrame
pushExternalVideoFrame pushExternalVideoFrame

集成方法

1. 集成声网 SDK 并实现互动直播功能

具体流程见声网 SDK 快速开始文档:

2. 实现 MV 文件音视频帧读取

使用 ijkplayer 等已经实现了完善的在线/本地 MV 文件读取和控制功能的第三方控件,获取到 MV 的音视频帧。

使用声网 SDK 的 pushExternalVideoFrame 接口,将视频帧数据传入声网 SDK。

在 声网 SDK 的 onRecordAudioFrame C++ 回调中,将 MV 的音频帧数据和 声网 SDK 采集到的歌唱者音频帧数据混合起来,实现人声和伴奏的混音。具体可参看 Demo 中 KTVKit 内部的实现。

你也可以直接使用 Demo 中的 KTVKit 类,该类已经将 MV 文件读取、混音、控制和传输都封装成简单的接口,方便调用。

3. 进阶功能

  1. 启用耳返功能,详见耳返

注意事项

  1. 开发者可以选择使用 demo 中封装好的 KTVKit 类以简化 MV 文件的读取和播放;
  2. 为了能将读取到的音视频帧数据回调出来输入给声网 SDK,Demo 中集成的 ijkplayer 经过了必要的改造,不能替换成其他版本的 ijkplayer 库;
  3. iOS Demo 中的 ijkplayer 为动态库,并包含了模拟器架构。在正式上传 Appstore 审核前需要手动将其中的模拟器架构去掉,避免影响审核;
  4. KTVKit 必须在加入频道前进行初始化。如果需要在频道中启用 KTVKit,需要先离开当前频道;
  5. KTVKit 类支持有一个或者两个音轨的 MV 文件,不支持第三根或者更多的音轨。如果 MV 文件有大于一根音轨,KTVKit 初始默认读取第二根音轨;
  6. KTVKit 类目前只支持 mp4 格式的 MV 文件。

常见问题调查

常见问题整理:一起 KTV FAQ

联系我们

  • 完整的 API 文档见 文档中心
  • 如果在集成中遇到问题,你可以到 开发者社区 提问。
  • 如果有售前咨询问题,可以拨打 400 632 6626,或加入官方 QQ 群 12742516 提问。
  • 如果需要售后技术支持,你可以在 Agora Dashboard 提交工单。
  • 如果发现了示例代码的 bug,欢迎提交 issue

代码许可

The MIT License (MIT).

# Agora Online KTV *Other language: [中文](README.zh.md)* ## Introduction Users can create karaoke television (KTV) rooms to perform the following: - Make voice or video calls with other users. - Play music videos (MVs). - Sing along with the MV. - Adjust the volume of their own voice and the MV music. ## Architecture Here is the architecture of the Agora Online KTV: ![KTV 架构图](Image/ktv_together.en.jpg) - The host (singer) plays local or online MV files. - The voice of the host and the music of the MV are locally mixed by the Agora Native SDK for Video and transmitted to the Agora SD-RTN along with the MV video. - The audience receives the mixed audio and the MV video through the Agora SD-RTN. ## Run the Sample App 1. Create a developer account at [agora.io](https://sso.agora.io/en/signup) and create a project in Dashboard to get the App ID. ![](Image/appid.en.jpg) 2. Download the [Agora Native SDK for Voice/Video](https://docs.agora.io/en/Interactive%20Broadcast/downloads). ![](Image/sdk.en.jpg) #### Android 1. Add the App ID in the `Android/Agora-Online-KTV/app/src/main/res/values/strings_config.xml` file of your project. ``` <string name="agora_app_id"><#YOUR APP ID#></string> ``` 2. Unpack the SDK and do the following: - Copy the `*.jar` file under the `libs` folder and save it to the `Android/Agora-Online-KTV/app/libs` folder of your project. - Copy the `arm64-v8a/x86/armeabi-v7a` file under the `libs` folder and save it to the `Android/Agora-Online-KTV/app/src/main/jniLibs` folder of your project. 3. Open your project in Android Studio and connect to an Android test device. Compile and run the sample app. ``` Development environment: - Android SDK API Level 16+. - Android Studio 3.1+. - Devices with audio and video support. - Android 4.1+. ``` #### iOS 1. Add the App ID in the `AgoraVideoViewController.m` file. ``` self.rtcEngine = [AgoraRtcEngineKit sharedEngineWithAppId:<#APP_ID#> delegate:self]; ``` 2. Unpack the SDK and copy the `AgoraRtcEngineKit.framework` file to the `iOS/Agora-Online-KTV/Agora-Online-KTV` folder of your project. 3. Open `iOS/Agora-Online-KTV/Agora-Online-KTV.xcodeproj` in Xcode. Connect to an iOS test device, fill in a valid developer signature and run the sample app. ``` Development environment: - Xcode 10.0+. - iOS 8.0+. ``` ## API methods ![](Image/ktv_api.en.jpg) The API methods related to the Agora Online KTV feature can be divided into two categories. ### Join a Channel and Make Voice/Video Calls - Creates an Agora RTC engine. - [`enableVideo`](https://docs.agora.io/en/Interactive%20Broadcast/API%20Reference/oc/Classes/AgoraRtcEngineKit.html#//api/name/enableVideo): Enables the video mode. - [`setVideoProfile`](https://docs.agora.io/en/Interactive%20Broadcast/API%20Reference/oc/Classes/AgoraRtcEngineKit.html#//api/name/setVideoProfile:swapWidthAndHeight:): Sets the video profile. - [`setChannelProfile`](https://docs.agora.io/en/Interactive%20Broadcast/API%20Reference/oc/Classes/AgoraRtcEngineKit.html#//api/name/setChannelProfile:): Sets the channel profile. - [`setClientRole`](https://docs.agora.io/en/Interactive%20Broadcast/API%20Reference/oc/Classes/AgoraRtcEngineKit.html#//api/name/setClientRole:):Sets the role of the user, such as a host or an audience (default). - [`setupLocalVideo`](https://docs.agora.io/en/Interactive%20Broadcast/API%20Reference/oc/Classes/AgoraRtcEngineKit.html#//api/name/setupLocalVideo:): Sets the local video view. - [`setupRemoteVideo`](https://docs.agora.io/en/Interactive%20Broadcast/API%20Reference/oc/Classes/AgoraRtcEngineKit.html#//api/name/setupRemoteVideo:): Sets the remote video view. - [`joinChannel`](https://docs.agora.io/en/Interactive%20Broadcast/API%20Reference/oc/Classes/AgoraRtcEngineKit.html#//api/name/joinChannelByToken:channelId:info:uid:joinSuccess:): Allows a user to join a channel. - [`leaveChannel`](https://docs.agora.io/en/Interactive%20Broadcast/API%20Reference/oc/Classes/AgoraRtcEngineKit.html#//api/name/leaveChannel:): Allows a user to leave the channel. - [`stopPreview`](https://docs.agora.io/en/Interactive%20Broadcast/API%20Reference/oc/Classes/AgoraRtcEngineKit.html#//api/name/stopPreview): Stops the local video preview and the video. ### Play and Control MV Files The following sample code abstracts a KTVKit class that controls the MV and pushes the video frames to the Agora SDK. - `create`: Creates KTVKit and passes it to the Agora SDK. - `openAndPlayVideoFile`: Opens and plays an MV file. - `pause` or `resume`: Pauses or resumes playback. - `stopPlayVideoFile`: Stops playback. - `switchAudioTrack`: Switches between the instrumental and vocal version of a song. - `resetAudioBuffer`: Resets the audio buffer. The SDK calls this method when the user role switches. - `adjustVoiceVolume`: Adjusts the voice volume (%). - `adjustAccompanyVolume`: Adjusts the music volume (%). - `getCurrentPosition`: Gets the MV playback position (%). - `getDuration`: Gets the MV playback duration (ms). #### Advanced functions 1. To enable the in-ear monitoring function, see [In-ear Monitoring](https://docs.agora.io/en/Interactive%20Broadcast/in-ear_android?platform=Android). ## FAQ [Online KTV FAQ](https://confluence.agora.io/display/CUS1/Online-KTV) ## Contact Us - API documentation is available at the [Document Center](https://docs.agora.io/en/). - For any issue with integration, connect with global developers in the [Developer Community](https://dev.agora.io/en/). - For any question about purchasing our service, contact [sales-us@agora.io](mailto:sales-us@agora.io). - For technical support, submit a ticket at [Dashboard](https://dashboard.agora.io). - For any bug in our sample code, submit an issue at [GitHub](https://github.com/AgoraIO/Agora-Online-KTV/issues). ## License The MIT License (MIT).

简介

声网KTV演示Demo 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/crwth/Online-KTV.git
git@gitee.com:crwth/Online-KTV.git
crwth
Online-KTV
Online-KTV
master

搜索帮助