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
2022-07-26 01:13:02 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2022-07-26 01:13:02 +0900
Commit
3294aca4000d392fb0d194a5bc6a039a8a473446
3294aca4
1 parent
02be503a
Route AudioSwitch calls through main thread (#120)
隐藏空白字符变更
内嵌
并排对比
正在显示
2 个修改的文件
包含
26 行增加
和
14 行删除
livekit-android-sdk/src/main/java/io/livekit/android/audio/AudioSwitchHandler.kt
sample-app-common/src/main/java/io/livekit/android/sample/CallViewModel.kt
livekit-android-sdk/src/main/java/io/livekit/android/audio/AudioSwitchHandler.kt
查看文件 @
3294aca
...
...
@@ -2,6 +2,8 @@ package io.livekit.android.audio
import android.content.Context
import android.media.AudioManager
import android.os.Handler
import android.os.Looper
import com.twilio.audioswitch.AudioDevice
import com.twilio.audioswitch.AudioDeviceChangeListener
import com.twilio.audioswitch.AudioSwitch
...
...
@@ -19,23 +21,32 @@ constructor(private val context: Context) : AudioHandler {
private var audioSwitch: AudioSwitch? = null
// AudioSwitch is not threadsafe, so all calls should be done on the main thread.
private val handler = Handler(Looper.getMainLooper())
override fun start() {
if (audioSwitch == null) {
val switch = AudioSwitch(
context = context,
loggingEnabled = loggingEnabled,
audioFocusChangeListener = onAudioFocusChangeListener ?: defaultOnAudioFocusChangeListener,
preferredDeviceList = preferredDeviceList ?: defaultPreferredDeviceList
)
audioSwitch = switch
switch.start(audioDeviceChangeListener ?: defaultAudioDeviceChangeListener)
switch.activate()
handler.removeCallbacksAndMessages(null)
handler.post {
val switch = AudioSwitch(
context = context,
loggingEnabled = loggingEnabled,
audioFocusChangeListener = onAudioFocusChangeListener ?: defaultOnAudioFocusChangeListener,
preferredDeviceList = preferredDeviceList ?: defaultPreferredDeviceList
)
audioSwitch = switch
switch.start(audioDeviceChangeListener ?: defaultAudioDeviceChangeListener)
switch.activate()
}
}
}
override fun stop() {
audioSwitch?.stop()
audioSwitch = null
handler.removeCallbacksAndMessages(null)
handler.post {
audioSwitch?.stop()
audioSwitch = null
}
}
val selectedAudioDevice: AudioDevice?
...
...
sample-app-common/src/main/java/io/livekit/android/sample/CallViewModel.kt
查看文件 @
3294aca
...
...
@@ -19,21 +19,23 @@ import io.livekit.android.room.participant.Participant
import io.livekit.android.room.participant.RemoteParticipant
import io.livekit.android.room.track.*
import io.livekit.android.util.flow
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import livekit.LivekitRtc
@OptIn(ExperimentalCoroutinesApi::class)
class CallViewModel(
val url: String,
val token: String,
application: Application
) : AndroidViewModel(application) {
val audioHandler = AudioSwitchHandler(application)
val room = LiveKit.create(
appContext = application,
options = RoomOptions(adaptiveStream = true, dynacast = true),
overrides = LiveKitOverrides(
audioHandler = audioHandler
)
)
val participants = room::remoteParticipants.flow
...
...
@@ -73,7 +75,6 @@ class CallViewModel(
private val mutablePermissionAllowed = MutableStateFlow(true)
val permissionAllowed = mutablePermissionAllowed.hide()
val audioHandler = AudioSwitchHandler(application)
init {
viewModelScope.launch {
launch {
...
...
请
注册
或
登录
后发表评论