Skip to content

Commit

Permalink
fix(demo): camera: fix switch to audio enable/disable for the camera …
Browse files Browse the repository at this point in the history
…streamer
  • Loading branch information
ThibaultBee committed Dec 2, 2024
1 parent 698d86f commit 6e08816
Showing 1 changed file with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ import kotlinx.coroutines.flow.StateFlow


class StreamerManager(
private val context: Context,
private val configuration: Configuration
private val context: Context, private val configuration: Configuration
) : IRotationProvider.Listener {
private var streamer: ICoroutineStreamer =
DefaultCameraStreamer(context, configuration.audio.enable)
Expand All @@ -71,8 +70,7 @@ class StreamerManager(
val requiredPermissions: List<String>
get() {
val permissions = mutableListOf(
Manifest.permission.CAMERA,
Manifest.permission.RECORD_AUDIO
Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO
)
// Only needed for File (MP4, TS, FLV,...)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
Expand Down Expand Up @@ -107,11 +105,15 @@ class StreamerManager(
@RequiresPermission(Manifest.permission.RECORD_AUDIO)
fun configureStreamer() {
require(configuration.video.enable || configuration.audio.enable) { "At least one of audio or video must be enabled" }

// Change streamer if needed
if (configuration.video.enable) {
if (streamer !is DefaultCameraStreamer) {
streamer = DefaultCameraStreamer(context, configuration.audio.enable)
} else {
if (((streamer.audioSource == null) && configuration.audio.enable) || ((streamer.audioSource != null) && !configuration.audio.enable)) {
streamer = DefaultCameraStreamer(context, configuration.audio.enable)
}
}
} else {
if (streamer !is DefaultAudioOnlyStreamer) {
Expand Down Expand Up @@ -156,53 +158,47 @@ class StreamerManager(
suspend fun startStream() {
val descriptor = when (configuration.endpoint.endpointType) {
EndpointType.TS_FILE -> UriMediaDescriptor(
context,
context.createVideoContentUri(
context, context.createVideoContentUri(
configuration.endpoint.file.filename.appendIfNotEndsWith(
FileExtension.TS.extension
)
)
)

EndpointType.FLV_FILE -> UriMediaDescriptor(
context,
context.createVideoContentUri(
context, context.createVideoContentUri(
configuration.endpoint.file.filename.appendIfNotEndsWith(
FileExtension.FLV.extension
)
)
)

EndpointType.MP4_FILE -> UriMediaDescriptor(
context,
context.createVideoContentUri(
context, context.createVideoContentUri(
configuration.endpoint.file.filename.appendIfNotEndsWith(
FileExtension.MP4.extension
)
)
)

EndpointType.WEBM_FILE -> UriMediaDescriptor(
context,
context.createVideoContentUri(
context, context.createVideoContentUri(
configuration.endpoint.file.filename.appendIfNotEndsWith(
FileExtension.WEBM.extension
)
)
)

EndpointType.OGG_FILE -> UriMediaDescriptor(
context,
context.createAudioContentUri(
context, context.createAudioContentUri(
configuration.endpoint.file.filename.appendIfNotEndsWith(
FileExtension.OGG.extension
)
)
)

EndpointType.THREEGP_FILE -> UriMediaDescriptor(
context,
context.createVideoContentUri(
context, context.createVideoContentUri(
configuration.endpoint.file.filename.appendIfNotEndsWith(
FileExtension.THREEGP.extension
)
Expand Down

0 comments on commit 6e08816

Please sign in to comment.