Live Streaming Kit
  • iOS
  • Android : Java
  • Web
  • Flutter
  • React Native
  • Overview
  • Quick start
    • Quick start
    • Quick start (with cohosting)
  • Enhance the livestream
    • PK battles
    • Screen sharing
    • Advanced beauty effects
    • Send virtual gifts
    • Use Tokens for authentication
  • Customize the livestream
    • Set avatar for users
    • Hide components
    • Set a leave confirmation dialog
    • Add custom UI components
    • Modify User Interface text
    • Customize the menu bar
    • Implement an audio-only live
    • Forcefully end a livestream room
    • Turn off camera during co-hosting
  • FAQs
  • API Reference
    • API
    • Event
  • Migration guide
  • Documentation
  • Live Streaming Kit
  • Quick start
  • Quick start

Quick start

Last updated:2023-09-13 10:34

Integrate the SDK

Add ZegoUIKitPrebuiltLiveStreaming as dependencies

  1. Add the jitpack configuration.
  • If your Android Gradle Plugin is 7.1.0 or later: enter your project's root directory, open the settings.gradle file to add the jitpack to dependencyResolutionManagement > repositories like this:
dependencyResolutionManagement {
   repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
   repositories {
      google()
      mavenCentral()
      maven { url 'https://storage.zego.im/maven' }  // <- Add this line.
      maven { url 'https://www.jitpack.io' } // <- Add this line.
   }
}

If you can't find the above fields in settings.gradle, it's probably because your Android Gradle Plugin version is lower than v7.1.0.

For more details, see Android Gradle Plugin Release Note v7.1.0.

  • If your Android Gradle Plugin is earlier than 7.1.0: enter your project's root directory, open the build.gradle file to add the jitpack to allprojects->repositories like this:
allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://storage.zego.im/maven' }   // <- Add this line.
        maven { url "https://jitpack.io" }  // <- Add this line.
    }
}
  1. Modify your app-level build.gradle file:
    dependencies {
     ...
     implementation 'com.github.ZEGOCLOUD:zego_uikit_prebuilt_live_streaming_android:+'    // Add this line to your module-level build.gradle file's dependencies, usually named [app].
    }

Using the ZegoUIKitPrebuiltLiveStreamingFragment in your project

  • Go to ZEGOCLOUD Admin Console, get the appID and appSign of your project.
  • Specify the userID and userName for connecting the Live Streaming Kit service.
  • liveID represents the live streaming you want to start or watch (only supports single-host live streaming for now).
  • userID, userName, and liveID can only contain numbers, letters, and underlines (_).
  • Using the same liveID will enter the same live streaming.

With the same liveID, only one user can enter the live stream as host. Other users need to enter the live stream as the audience.

Java Kotlin
public class LiveActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_call);

        addFragment();
    }

    public void addFragment() {
        long appID = yourAppID;
        String appSign = yourAppSign;
        String userID = yourUserID;
        String userName = yourUserName;

        boolean isHost = getIntent().getBooleanExtra("host", false);
        String liveID = getIntent().getStringExtra("liveID");

        ZegoUIKitPrebuiltLiveStreamingConfig config;
        if (isHost) {
            config = ZegoUIKitPrebuiltLiveStreamingConfig.host();
        } else {
            config = ZegoUIKitPrebuiltLiveStreamingConfig.audience();
        }
        ZegoUIKitPrebuiltLiveStreamingFragment fragment = ZegoUIKitPrebuiltCallFragment.newInstance(
            appID, appSign, userID, userName,liveID,config);
        getSupportFragmentManager().beginTransaction()
            .replace(R.id.fragment_container, fragment)
            .commitNow();
    }
}
class LiveActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_live)
        addFragment()
    }

    private fun addFragment() {
        val appID: Long = yourAppID
        val appSign = yourAppSign
        val userID = YourUserID
        val userName = YourUserName

        val isHost = intent.getBooleanExtra("host", false)
        val liveID = intent.getStringExtra("liveID")

        val config: ZegoUIKitPrebuiltLiveStreamingConfig = if (isHost) {
            ZegoUIKitPrebuiltLiveStreamingConfig.host()
        } else {
            ZegoUIKitPrebuiltLiveStreamingConfig.audience()
        }
        val fragment = ZegoUIKitPrebuiltLiveStreamingFragment.newInstance(
            appID, appSign, userID, userName, liveID, config
        )
        supportFragmentManager.beginTransaction()
            .replace(R.id.fragment_container, fragment)
            .commitNow()
    }
}

Then, you can start live streaming by starting your LiveActivity.

Run & Test

Now you have finished all the steps!

You can simply click the Run on Android Studio to run and test your App on the device.

Resources

Page Directory