名称 最后更新
.github/workflows 正在载入提交数据...
.idea 正在载入提交数据...
gradle 正在载入提交数据...
livekit-android-sdk 正在载入提交数据...
sample-app-common 正在载入提交数据...
sample-app-compose 正在载入提交数据...
sample-app 正在载入提交数据...
.gitignore 正在载入提交数据...
.gitmodules 正在载入提交数据...
LICENSE 正在载入提交数据...
NOTICE 正在载入提交数据...
README.md 正在载入提交数据...
build.gradle 正在载入提交数据...
gradle.properties 正在载入提交数据...
gradlew 正在载入提交数据...
gradlew.bat 正在载入提交数据...
release-instructions.md 正在载入提交数据...
settings.gradle 正在载入提交数据...
protocol @ 8de3224f

Android Kotlin SDK for LiveKit

Official Android Client SDK for LiveKit. Easily add video & audio capabilities to your Android apps.

Docs

Docs and guides at https://docs.livekit.io

Installation

LiveKit for Android is available as a Maven package.

```groovy title="build.gradle" ... dependencies { implementation "io.livekit:livekit-android:" }


## Sample App

There are two sample apps with similar functionality:

* [Compose app](https://github.com/livekit/client-sdk-android/tree/master/sample-app-compose/src/main/java/io/livekit/android/composesample) 
* [Standard app](https://github.com/livekit/client-sdk-android/tree/master/sample-app)

## Usage

### Permissions

LiveKit relies on the `RECORD_AUDIO` and `CAMERA` permissions to use the microphone and camera.
These permission must be requested at runtime. Reference the [sample app](https://github.com/livekit/client-sdk-android/blob/4e76e36e0d9f895c718bd41809ab5ff6c57aabd4/sample-app-compose/src/main/java/io/livekit/android/composesample/MainActivity.kt#L134) for an example.

### Publishing camera and microphone

```kt
room.localParticipant.setCameraEnabled(true)
room.localParticipant.setMicrophoneEnabled(true)

Sharing screen

// create an intent launcher for screen capture
// this *must* be registered prior to onCreate(), ideally as an instance val
val screenCaptureIntentLauncher = registerForActivityResult(
    ActivityResultContracts.StartActivityForResult()
) { result ->
    val resultCode = result.resultCode
    val data = result.data
    if (resultCode != Activity.RESULT_OK || data == null) {
        return@registerForActivityResult
    }
    lifecycleScope.launch {
        room.localParticipant.setScreenShareEnabled(true, data)
    }
}

// when it's time to enable the screen share, perform the following
val mediaProjectionManager =
    getSystemService(MEDIA_PROJECTION_SERVICE) as MediaProjectionManager
screenCaptureIntentLauncher.launch(mediaProjectionManager.createScreenCaptureIntent())

Rendering subscribed tracks

LiveKit uses WebRTC-provided org.webrtc.SurfaceViewRenderer to render video tracks. Subscribed audio tracks are automatically played.

class MainActivity : AppCompatActivity(), RoomListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ...
        val url = "wss://your_host";
        val token = "your_token"

        launch {
            val room = LiveKit.connect(
                applicationContext,
                url,
                token,
                ConnectOptions(),
                this
            )
            val localParticipant = room.localParticipant
            localParticipant.setMicrophoneEnabled(true)
            localParticipant.setCameraEnabled(true)

            attachVideo(videoTrack)
        }
    }

    override fun onTrackSubscribed(
        track: Track,
        publication: RemoteTrackPublication,
        participant: RemoteParticipant,
        room: Room
    ) {
        if (track is VideoTrack) {
            attachVideo(track)
        }
    }

    private fun attachVideo(videoTrack: VideoTrack) {
        // viewBinding.renderer is a `org.webrtc.SurfaceViewRenderer` in your
        // layout
        videoTrack.addRenderer(viewBinding.renderer)
    }
}

Dev Environment

To develop the Android SDK or running the sample app, you'll need:

For those developing on Apple M1 Macs, please add below to $HOME/.gradle/gradle.properties

protoc_platform=osx-x86_64

Optional (Dev convenience)

  1. Download webrtc sources from https://webrtc.googlesource.com/src
  2. Add sources to Android Studio by pointing at the webrtc/sdk/android folder.