Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
xuning
/
livekitAndroidXuningTest
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
davidliu
2024-08-15 19:21:44 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2024-08-15 19:21:44 +0900
Commit
886f3c34fd5f873d857382c0232e19a1ae2c2f5b
886f3c34
1 parent
8b041860
Add self camera preview to basic example app (#479)
* Self camera * spotless
显示空白字符变更
内嵌
并排对比
正在显示
2 个修改的文件
包含
37 行增加
和
0 行删除
sample-app-basic/src/main/java/io/livekit/android/sample/basic/MainActivity.kt
sample-app-basic/src/main/res/layout/activity_main.xml
sample-app-basic/src/main/java/io/livekit/android/sample/basic/MainActivity.kt
查看文件 @
886f3c3
/*
* Copyright 2024 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.livekit.android.sample.basic
import android.Manifest
...
...
@@ -13,7 +29,9 @@ import io.livekit.android.LiveKit
import io.livekit.android.events.RoomEvent
import io.livekit.android.events.collect
import io.livekit.android.renderer.SurfaceViewRenderer
import io.livekit.android.renderer.TextureViewRenderer
import io.livekit.android.room.Room
import io.livekit.android.room.track.LocalVideoTrack
import io.livekit.android.room.track.Track
import io.livekit.android.room.track.VideoTrack
import kotlinx.coroutines.launch
...
...
@@ -32,6 +50,7 @@ class MainActivity : AppCompatActivity() {
// Setup the video renderer
room.initVideoRenderer(findViewById<SurfaceViewRenderer>(R.id.renderer))
room.initVideoRenderer(findViewById<TextureViewRenderer>(R.id.local_camera))
requestNeededPermissions { connectToRoom() }
}
...
...
@@ -62,6 +81,12 @@ class MainActivity : AppCompatActivity() {
localParticipant.setMicrophoneEnabled(true)
localParticipant.setCameraEnabled(true)
// Attach local video camera
val localTrack = localParticipant.getTrackPublication(Track.Source.CAMERA)?.track as? LocalVideoTrack
if (localTrack != null) {
attachLocalVideo(localTrack)
}
// Attach video of remote participant if already available.
val remoteVideoTrack = room.remoteParticipants.values.firstOrNull()
?.getTrackPublication(Track.Source.CAMERA)
...
...
@@ -85,6 +110,10 @@ class MainActivity : AppCompatActivity() {
findViewById<View>(R.id.progress).visibility = View.GONE
}
private fun attachLocalVideo(videoTrack: VideoTrack) {
videoTrack.addRenderer(findViewById<SurfaceViewRenderer>(R.id.local_camera))
}
private fun requestNeededPermissions(onHasPermissions: () -> Unit) {
val requestPermissionLauncher =
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { grants ->
...
...
sample-app-basic/src/main/res/layout/activity_main.xml
查看文件 @
886f3c3
...
...
@@ -10,6 +10,14 @@
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
<io.livekit.android.renderer.TextureViewRenderer
android:id=
"@+id/local_camera"
android:layout_width=
"150dp"
android:layout_height=
"150dp"
android:layout_gravity=
"bottom|end"
android:layout_margin=
"10dp"
/>
<ProgressBar
android:id=
"@+id/progress"
android:layout_width=
"wrap_content"
...
...
请
注册
或
登录
后发表评论