Moved playRecording function from Utils to CallDetailsAdapter
This commit is contained in:
@@ -3,6 +3,7 @@ package com.tutpro.baresip
|
|||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
|
import android.media.AudioAttributes
|
||||||
import android.media.MediaPlayer
|
import android.media.MediaPlayer
|
||||||
import android.text.format.DateUtils
|
import android.text.format.DateUtils
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
@@ -12,8 +13,10 @@ import android.widget.ArrayAdapter
|
|||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.core.content.ContextCompat
|
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.DateFormat
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -83,7 +86,7 @@ class CallDetailsAdapter(private val ctx: Context, private val rows: ArrayList<C
|
|||||||
if (!decPlayer.isPlaying && !encPlayer.isPlaying) {
|
if (!decPlayer.isPlaying && !encPlayer.isPlaying) {
|
||||||
decPlayer.reset()
|
decPlayer.reset()
|
||||||
encPlayer.reset()
|
encPlayer.reset()
|
||||||
Utils.playRecording(ctx, viewHolder.durationView, recording, decPlayer, encPlayer)
|
playRecording(ctx, viewHolder.durationView, recording)
|
||||||
} else if (decPlayer.isPlaying && encPlayer.isPlaying) {
|
} else if (decPlayer.isPlaying && encPlayer.isPlaying) {
|
||||||
decPlayer.stop()
|
decPlayer.stop()
|
||||||
encPlayer.stop()
|
encPlayer.stop()
|
||||||
@@ -96,4 +99,69 @@ class CallDetailsAdapter(private val ctx: Context, private val rows: ArrayList<C
|
|||||||
|
|
||||||
return rowView
|
return rowView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun playRecording(ctx: Context, textView: TextView, recording: Array<String>) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -995,71 +995,6 @@ object Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun playRecording(ctx: Context, textView: TextView, recording: Array<String>,
|
|
||||||
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")
|
@Suppress("unused")
|
||||||
fun playFile(ctx: Context, path: String) {
|
fun playFile(ctx: Context, path: String) {
|
||||||
Log.d(TAG, "Playing file $path")
|
Log.d(TAG, "Playing file $path")
|
||||||
|
|||||||
Reference in New Issue
Block a user