TUIKaraoke is an open-source audio/video UI component that you can integrate into your project to bring online karaoke, seat management, gift giving/receiving, text chat, and other TRTC features to your application. TUIKaraoke requires only a few lines of code and also supports the iOS platform. Its basic features are shown below:
Component Integration
Step 1. Download and import the TUIKaraoke component
Go to GitHub, clone or download the code, copy the Source and Debug directories in the Android directory to your project, and complete the following import operations:
Complete import in setting.gradle as shown below:
include ':Source'
include ':Debug'
Add dependencies on TUIKaraoke to the build.gradle file in app:
api project(':Source')
Add dependencies on TRTC SDK and IM SDK to the build.gradle file in the root directory:
Step 2. Configure permission requests and obfuscation rules
Configure permission requests for your app in AndroidManifest.xml. The SDKs need the following permissions (on Android 6.0 and later, the mic access and storage read permission must be requested at runtime):
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> // Use case: This permission is required for the floating window
SDKAppID: TRTC application ID. If you haven't activated the TRTC service, log in to the TRTC console, create a TRTC application, and click Application Info. The SDKAppID is as shown below:
Secretkey: TRTC application key, which corresponds to SDKAppID. On the Application Management page in the TRTC console, the SecretKey is as shown below:
userId: Current user ID, which is a string and can contain up to 32 bytes of letters and digits (special symbols are not supported). You can customize it based on your actual account system.
userSig: Security protection signature calculated based on SDKAppID, userId, and Secretkey. You can click here to directly generate a debugging userSig online. For more information, see UserSig.
4. Play back songs and try out the karaoke scenario
You can get the music ID and URL to play back a song based on your business. For more information, see Music Playback APIs.
// Play back the music
mTRTCKaraokeRoom.startPlayMusic(musicID,url);
// Stop the music
mTRTCKaraokeRoom.stopPlayMusic();
After completing the previous steps, you can implement the basic karaoke features. If your business needs more features such as text chat and gift giving, you can integrate the following capabilities:
Step 5. Add the text chat feature (optional)
If you want the text chat feature between anchors and listeners, implement message sending/receiving as follows:
For more information on relevant APIs, see sendRoomTextMsg.