Improved starting/stopping of recording play
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import android.media.MediaPlayer
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
@ -11,6 +12,8 @@ class CallDetailsActivity : AppCompatActivity() {
|
||||
private lateinit var binding: ActivityCallDetailsBinding
|
||||
private lateinit var aor: String
|
||||
private lateinit var peer: String
|
||||
private val decPlayer = MediaPlayer()
|
||||
private val encPlayer = MediaPlayer()
|
||||
private var position = 0
|
||||
|
||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||
@ -38,7 +41,8 @@ class CallDetailsActivity : AppCompatActivity() {
|
||||
headerView.text = headerText
|
||||
|
||||
val listView = binding.calls
|
||||
listView.adapter = CallDetailsAdapter(this, CallsActivity.uaHistory[position].details)
|
||||
listView.adapter = CallDetailsAdapter(this, CallsActivity.uaHistory[position].details,
|
||||
decPlayer, encPlayer)
|
||||
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
}
|
||||
@ -65,6 +69,10 @@ class CallDetailsActivity : AppCompatActivity() {
|
||||
|
||||
private fun goBack() {
|
||||
BaresipService.activities.remove("call_details,$aor,$peer,$position")
|
||||
decPlayer.stop()
|
||||
decPlayer.release()
|
||||
encPlayer.stop()
|
||||
encPlayer.release()
|
||||
finish()
|
||||
}
|
||||
|
||||
|
||||
@ -17,8 +17,9 @@ import java.text.SimpleDateFormat
|
||||
|
||||
import java.util.*
|
||||
|
||||
class CallDetailsAdapter(private val ctx: Context, private val rows: ArrayList<CallRow.Details>) :
|
||||
ArrayAdapter<CallRow.Details>(ctx, R.layout.call_detail_row, rows) {
|
||||
class CallDetailsAdapter(private val ctx: Context, private val rows: ArrayList<CallRow.Details>,
|
||||
private val decPlayer: MediaPlayer, private val encPlayer: MediaPlayer) :
|
||||
ArrayAdapter<CallRow.Details>(ctx, R.layout.call_detail_row, rows) {
|
||||
|
||||
private val layoutInflater =
|
||||
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
@ -78,14 +79,15 @@ class CallDetailsAdapter(private val ctx: Context, private val rows: ArrayList<C
|
||||
val recording = rows[position].recording
|
||||
if (recording[0] != "") {
|
||||
viewHolder.durationView.typeface = Typeface.DEFAULT_BOLD
|
||||
var players: Array<MediaPlayer>? = null
|
||||
viewHolder.durationView.setOnClickListener {
|
||||
if (players == null || (!players!![0].isPlaying && !players!![1].isPlaying)) {
|
||||
players = Utils.playRecording(ctx, recording)
|
||||
} else {
|
||||
players!![0].stop()
|
||||
players!![1].stop()
|
||||
players = null
|
||||
if (!decPlayer.isPlaying && !encPlayer.isPlaying) {
|
||||
decPlayer.reset()
|
||||
encPlayer.reset()
|
||||
Utils.playRecording(ctx, viewHolder.durationView, recording, decPlayer, encPlayer)
|
||||
} else if (decPlayer.isPlaying && encPlayer.isPlaying) {
|
||||
decPlayer.stop()
|
||||
encPlayer.stop()
|
||||
viewHolder.durationView.setTextColor(ContextCompat.getColor(ctx, R.color.colorItemText))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -995,10 +995,9 @@ object Utils {
|
||||
}
|
||||
}
|
||||
|
||||
fun playRecording(ctx: Context, recording: Array<String>): Array<MediaPlayer> {
|
||||
Log.d(TAG, "Playing recording $recording")
|
||||
val decPlayer = MediaPlayer()
|
||||
val encPlayer = MediaPlayer()
|
||||
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()
|
||||
@ -1017,12 +1016,13 @@ object Utils {
|
||||
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()
|
||||
it.release()
|
||||
textView.setTextColor(ContextCompat.getColor(ctx, R.color.colorItemText))
|
||||
}
|
||||
try {
|
||||
val file = recording[0]
|
||||
@ -1042,7 +1042,6 @@ object Utils {
|
||||
setOnCompletionListener {
|
||||
Log.d(TAG, "Stopping decPlayer")
|
||||
it.stop()
|
||||
it.release()
|
||||
}
|
||||
try {
|
||||
val file = recording[1]
|
||||
@ -1058,7 +1057,7 @@ object Utils {
|
||||
Log.e(TAG, "decPlayer Exception: $e")
|
||||
}
|
||||
}
|
||||
return arrayOf(encPlayer, decPlayer)
|
||||
return
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
|
||||
Reference in New Issue
Block a user