Committed by
GitHub
Docs updates to reflect high level API. Fixed compilation on M1 Macs (#26)
正在显示
2 个修改的文件
包含
59 行增加
和
7 行删除
| @@ -17,8 +17,53 @@ dependencies { | @@ -17,8 +17,53 @@ dependencies { | ||
| 17 | } | 17 | } |
| 18 | ``` | 18 | ``` |
| 19 | 19 | ||
| 20 | +## Sample App | ||
| 21 | + | ||
| 22 | +There are two sample apps with similar functionality: | ||
| 23 | + | ||
| 24 | +* [Compose app](https://github.com/livekit/client-sdk-android/tree/master/sample-app-compose/src/main/java/io/livekit/android/composesample) | ||
| 25 | +* [Standard app](https://github.com/livekit/client-sdk-android/tree/master/sample-app) | ||
| 26 | + | ||
| 20 | ## Usage | 27 | ## Usage |
| 21 | 28 | ||
| 29 | +### Permissions | ||
| 30 | + | ||
| 31 | +LiveKit relies on the `RECORD_AUDIO` and `CAMERA` permissions to use the microphone and camera. | ||
| 32 | +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. | ||
| 33 | + | ||
| 34 | +### Publishing camera and microphone | ||
| 35 | + | ||
| 36 | +```kt | ||
| 37 | +room.localParticipant.setCameraEnabled(true) | ||
| 38 | +room.localParticipant.setMicrophoneEnabled(true) | ||
| 39 | +``` | ||
| 40 | + | ||
| 41 | +### Sharing screen | ||
| 42 | + | ||
| 43 | +```kt | ||
| 44 | +// create an intent launcher for screen capture | ||
| 45 | +// this *must* be registered prior to onCreate(), ideally as an instance val | ||
| 46 | +val screenCaptureIntentLauncher = registerForActivityResult( | ||
| 47 | + ActivityResultContracts.StartActivityForResult() | ||
| 48 | +) { result -> | ||
| 49 | + val resultCode = result.resultCode | ||
| 50 | + val data = result.data | ||
| 51 | + if (resultCode != Activity.RESULT_OK || data == null) { | ||
| 52 | + return@registerForActivityResult | ||
| 53 | + } | ||
| 54 | + lifecycleScope.launch { | ||
| 55 | + room.localParticipant.setScreenShareEnabled(true, data) | ||
| 56 | + } | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +// when it's time to enable the screen share, perform the following | ||
| 60 | +val mediaProjectionManager = | ||
| 61 | + getSystemService(MEDIA_PROJECTION_SERVICE) as MediaProjectionManager | ||
| 62 | +screenCaptureIntentLauncher.launch(mediaProjectionManager.createScreenCaptureIntent()) | ||
| 63 | +``` | ||
| 64 | + | ||
| 65 | +### Rendering subscribed tracks | ||
| 66 | + | ||
| 22 | LiveKit uses WebRTC-provided `org.webrtc.SurfaceViewRenderer` to render video tracks. Subscribed audio tracks are automatically played. | 67 | LiveKit uses WebRTC-provided `org.webrtc.SurfaceViewRenderer` to render video tracks. Subscribed audio tracks are automatically played. |
| 23 | 68 | ||
| 24 | ```kt | 69 | ```kt |
| @@ -64,18 +109,19 @@ class MainActivity : AppCompatActivity(), RoomListener { | @@ -64,18 +109,19 @@ class MainActivity : AppCompatActivity(), RoomListener { | ||
| 64 | } | 109 | } |
| 65 | ``` | 110 | ``` |
| 66 | 111 | ||
| 67 | -### Permissions | ||
| 68 | - | ||
| 69 | -LiveKit relies on the `RECORD_AUDIO` and `CAMERA` permissions to use the microphone and camera. | ||
| 70 | -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. | ||
| 71 | - | ||
| 72 | ## Dev Environment | 112 | ## Dev Environment |
| 73 | 113 | ||
| 74 | -To develop the Android SDK itself, you'll need: | 114 | +To develop the Android SDK or running the sample app, you'll need: |
| 75 | 115 | ||
| 76 | - Ensure the protocol submodule repo is initialized and updated with `git submodule update --init` | 116 | - Ensure the protocol submodule repo is initialized and updated with `git submodule update --init` |
| 77 | - Install [Android Studio Arctic Fox 2020.3.1+](https://developer.android.com/studio) | 117 | - Install [Android Studio Arctic Fox 2020.3.1+](https://developer.android.com/studio) |
| 78 | 118 | ||
| 119 | +For those developing on Apple M1 Macs, please add below to $HOME/.gradle/gradle.properties | ||
| 120 | + | ||
| 121 | +``` | ||
| 122 | +protoc_platform=osx-x86_64 | ||
| 123 | +``` | ||
| 124 | + | ||
| 79 | ### Optional (Dev convenience) | 125 | ### Optional (Dev convenience) |
| 80 | 126 | ||
| 81 | 1. Download webrtc sources from https://webrtc.googlesource.com/src | 127 | 1. Download webrtc sources from https://webrtc.googlesource.com/src |
| @@ -50,8 +50,14 @@ android { | @@ -50,8 +50,14 @@ android { | ||
| 50 | 50 | ||
| 51 | protobuf { | 51 | protobuf { |
| 52 | protoc { | 52 | protoc { |
| 53 | - artifact = "com.google.protobuf:protoc:${versions.protobuf}" | 53 | + // for apple m1, please add protoc_platform=osx-x86_64 in $HOME/.gradle/gradle.properties |
| 54 | + if (project.hasProperty('protoc_platform')) { | ||
| 55 | + artifact = "com.google.protobuf:protoc:${versions.protobuf}:${protoc_platform}" | ||
| 56 | + } else { | ||
| 57 | + artifact = "com.google.protobuf:protoc:${versions.protobuf}" | ||
| 58 | + } | ||
| 54 | } | 59 | } |
| 60 | + | ||
| 55 | generateProtoTasks { | 61 | generateProtoTasks { |
| 56 | all().each { task -> | 62 | all().each { task -> |
| 57 | task.builtins { | 63 | task.builtins { |
-
请 注册 或 登录 后发表评论