From 5abc223db8753f16f397d9cd42e7d5323d58e2cd Mon Sep 17 00:00:00 2001 From: Seyed Mostafa Hasani Date: Mon, 15 Jul 2024 13:31:32 +0330 Subject: [PATCH] refactor(android): migrate AudioOutput to Kotlin (#3993) * Rename .java to .kt * refactor(android): migrate AudioOutput to Kotlin * fix: lint error * refactor: rename of variables --- .../com/brentvatne/exoplayer/AudioOutput.java | 38 ------------------- .../com/brentvatne/exoplayer/AudioOutput.kt | 25 ++++++++++++ 2 files changed, 25 insertions(+), 38 deletions(-) delete mode 100644 android/src/main/java/com/brentvatne/exoplayer/AudioOutput.java create mode 100644 android/src/main/java/com/brentvatne/exoplayer/AudioOutput.kt diff --git a/android/src/main/java/com/brentvatne/exoplayer/AudioOutput.java b/android/src/main/java/com/brentvatne/exoplayer/AudioOutput.java deleted file mode 100644 index 90cd4f45..00000000 --- a/android/src/main/java/com/brentvatne/exoplayer/AudioOutput.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.brentvatne.exoplayer; - -import android.annotation.SuppressLint; - -import androidx.annotation.NonNull; -import androidx.media3.common.C; - -@SuppressLint("InlinedApi") -public enum AudioOutput { - SPEAKER("speaker", C.STREAM_TYPE_MUSIC), - EARPIECE("earpiece", C.STREAM_TYPE_VOICE_CALL); - - private final @C.StreamType int streamType; - private final String mName; - - AudioOutput(final String name, @C.StreamType int stream) { - mName = name; - streamType = stream; - } - - public static AudioOutput get(String name) { - for (AudioOutput d : values()) { - if (d.mName.equalsIgnoreCase(name)) - return d; - } - return SPEAKER; - } - - public int getStreamType() { - return streamType; - } - - @NonNull - @Override - public String toString() { - return getClass().getSimpleName() + "(" + this.mName + ", " + streamType + ")"; - } -} \ No newline at end of file diff --git a/android/src/main/java/com/brentvatne/exoplayer/AudioOutput.kt b/android/src/main/java/com/brentvatne/exoplayer/AudioOutput.kt new file mode 100644 index 00000000..7022600a --- /dev/null +++ b/android/src/main/java/com/brentvatne/exoplayer/AudioOutput.kt @@ -0,0 +1,25 @@ +package com.brentvatne.exoplayer + +import android.annotation.SuppressLint +import androidx.media3.common.C + +@SuppressLint("InlinedApi") +enum class AudioOutput(private val outputName: String, @C.StreamType val streamType: Int) { + + SPEAKER("speaker", C.STREAM_TYPE_MUSIC), + EARPIECE("earpiece", C.STREAM_TYPE_VOICE_CALL); + + companion object { + @JvmStatic + fun get(name: String): AudioOutput { + for (entry in entries) { + if (entry.outputName.equals(name, ignoreCase = true)) { + return entry + } + } + return SPEAKER + } + } + + override fun toString(): String = "${javaClass.simpleName}($outputName, $streamType)" +}