diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallDetailsAdapter.kt b/app/src/main/kotlin/com/tutpro/baresip/CallDetailsAdapter.kt index 1a80d031..4bf4f00e 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallDetailsAdapter.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallDetailsAdapter.kt @@ -3,6 +3,7 @@ package com.tutpro.baresip import android.annotation.SuppressLint import android.content.Context import android.graphics.Typeface +import android.media.AudioAttributes import android.media.MediaPlayer import android.text.format.DateUtils import android.view.LayoutInflater @@ -12,8 +13,10 @@ import android.widget.ArrayAdapter import android.widget.ImageView import android.widget.TextView import androidx.core.content.ContextCompat +import androidx.core.net.toUri +import java.io.File +import java.io.IOException import java.text.DateFormat -import java.text.SimpleDateFormat import java.util.* @@ -83,7 +86,7 @@ class CallDetailsAdapter(private val ctx: Context, private val rows: ArrayList) { + Log.d(TAG, "Playing recordings ${recording[0]} and ${recording[1]}") + decPlayer.apply { + setAudioAttributes( + AudioAttributes.Builder() + .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) + .setUsage(AudioAttributes.USAGE_MEDIA) + .build() + ) + setOnPreparedListener { + encPlayer.apply { + setAudioAttributes( + AudioAttributes.Builder() + .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) + .setUsage(AudioAttributes.USAGE_MEDIA) + .build() + ) + setOnPreparedListener { + it.start() + decPlayer.start() + textView.setTextColor(ContextCompat.getColor(ctx, R.color.colorAccent)) + Log.d(TAG, "Started players") + } + setOnCompletionListener { + Log.d(TAG, "Stopping encPlayer") + it.stop() + textView.setTextColor(ContextCompat.getColor(ctx, R.color.colorItemText)) + } + try { + val file = recording[0] + val encFile = File(file).copyTo(File(BaresipService.filesPath + "/tmp/encode.wav"), true) + val encUri = encFile.toUri() + setDataSource(ctx, encUri) + prepareAsync() + } catch (e: IllegalArgumentException) { + Log.e(TAG, "encPlayer IllegalArgumentException: $e") + } catch (e: IOException) { + Log.e(TAG, "encPlayer IOException: $e") + } catch (e: Exception) { + Log.e(TAG, "encPlayer Exception: $e") + } + } + } + setOnCompletionListener { + Log.d(TAG, "Stopping decPlayer") + it.stop() + } + try { + val file = recording[1] + val decFile = File(file).copyTo(File(BaresipService.filesPath + "/tmp/decode.wav"), true) + val decUri = decFile.toUri() + setDataSource(ctx, decUri) + prepareAsync() + } catch (e: IllegalArgumentException) { + Log.e(TAG, "decPlayer IllegalArgumentException: $e") + } catch (e: IOException) { + Log.e(TAG, "decPlayer IOException: $e") + } catch (e: Exception) { + Log.e(TAG, "decPlayer Exception: $e") + } + } + return + } + } diff --git a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt index 93d33775..f519928c 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt @@ -995,71 +995,6 @@ object Utils { } } - fun playRecording(ctx: Context, textView: TextView, recording: Array, - decPlayer: MediaPlayer, encPlayer: MediaPlayer) { - Log.d(TAG, "Playing recordings ${recording[0]} and ${recording[1]}") - decPlayer.apply { - setAudioAttributes( - AudioAttributes.Builder() - .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) - .setUsage(AudioAttributes.USAGE_MEDIA) - .build() - ) - setOnPreparedListener { - encPlayer.apply { - setAudioAttributes( - AudioAttributes.Builder() - .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) - .setUsage(AudioAttributes.USAGE_MEDIA) - .build() - ) - setOnPreparedListener { - it.start() - decPlayer.start() - textView.setTextColor(ContextCompat.getColor(ctx, R.color.colorAccent)) - Log.d(TAG, "Started players") - } - setOnCompletionListener { - Log.d(TAG, "Stopping encPlayer") - it.stop() - textView.setTextColor(ContextCompat.getColor(ctx, R.color.colorItemText)) - } - try { - val file = recording[0] - val encFile = File(file).copyTo(File(BaresipService.filesPath + "/tmp/encode.wav"), true) - val encUri = encFile.toUri() - setDataSource(ctx, encUri) - prepareAsync() - } catch (e: IllegalArgumentException) { - Log.e(TAG, "encPlayer IllegalArgumentException: $e") - } catch (e: IOException) { - Log.e(TAG, "encPlayer IOException: $e") - } catch (e: Exception) { - Log.e(TAG, "encPlayer Exception: $e") - } - } - } - setOnCompletionListener { - Log.d(TAG, "Stopping decPlayer") - it.stop() - } - try { - val file = recording[1] - val decFile = File(file).copyTo(File(BaresipService.filesPath + "/tmp/decode.wav"), true) - val decUri = decFile.toUri() - setDataSource(ctx, decUri) - prepareAsync() - } catch (e: IllegalArgumentException) { - Log.e(TAG, "decPlayer IllegalArgumentException: $e") - } catch (e: IOException) { - Log.e(TAG, "decPlayer IOException: $e") - } catch (e: Exception) { - Log.e(TAG, "decPlayer Exception: $e") - } - } - return - } - @Suppress("unused") fun playFile(ctx: Context, path: String) { Log.d(TAG, "Playing file $path")