Simplified playing of ringtone
This commit is contained in:
@ -51,6 +51,7 @@ class BaresipService: Service() {
|
|||||||
|
|
||||||
internal lateinit var intent: Intent
|
internal lateinit var intent: Intent
|
||||||
private lateinit var am: AudioManager
|
private lateinit var am: AudioManager
|
||||||
|
private lateinit var rt: Ringtone
|
||||||
private lateinit var nt: Ringtone
|
private lateinit var nt: Ringtone
|
||||||
private lateinit var nm: NotificationManager
|
private lateinit var nm: NotificationManager
|
||||||
private lateinit var snb: NotificationCompat.Builder
|
private lateinit var snb: NotificationCompat.Builder
|
||||||
@ -69,7 +70,6 @@ class BaresipService: Service() {
|
|||||||
private lateinit var stopState: String
|
private lateinit var stopState: String
|
||||||
private lateinit var quitTimer: CountDownTimer
|
private lateinit var quitTimer: CountDownTimer
|
||||||
|
|
||||||
private var rt: Ringtone? = null
|
|
||||||
private var rtTimer: Timer? = null
|
private var rtTimer: Timer? = null
|
||||||
private var vbTimer: Timer? = null
|
private var vbTimer: Timer? = null
|
||||||
private var origVolume = mutableMapOf<Int, Int>()
|
private var origVolume = mutableMapOf<Int, Int>()
|
||||||
@ -100,6 +100,10 @@ class BaresipService: Service() {
|
|||||||
RingtoneManager.TYPE_NOTIFICATION)
|
RingtoneManager.TYPE_NOTIFICATION)
|
||||||
nt = RingtoneManager.getRingtone(applicationContext, ntUri)
|
nt = RingtoneManager.getRingtone(applicationContext, ntUri)
|
||||||
|
|
||||||
|
val rtUri = RingtoneManager.getActualDefaultRingtoneUri(applicationContext,
|
||||||
|
RingtoneManager.TYPE_RINGTONE)
|
||||||
|
rt = RingtoneManager.getRingtone(applicationContext, rtUri)
|
||||||
|
|
||||||
nm = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
nm = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||||
createNotificationChannels()
|
createNotificationChannels()
|
||||||
snb = NotificationCompat.Builder(this, DEFAULT_CHANNEL_ID)
|
snb = NotificationCompat.Builder(this, DEFAULT_CHANNEL_ID)
|
||||||
@ -1197,24 +1201,16 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun startRinging() {
|
private fun startRinging() {
|
||||||
if (rt == null) {
|
|
||||||
val rtUri = RingtoneManager.getActualDefaultRingtoneUri(
|
|
||||||
applicationContext,
|
|
||||||
RingtoneManager.TYPE_RINGTONE
|
|
||||||
)
|
|
||||||
rt = RingtoneManager.getRingtone(applicationContext, rtUri)
|
|
||||||
}
|
|
||||||
if (VERSION.SDK_INT >= 28) {
|
if (VERSION.SDK_INT >= 28) {
|
||||||
rt!!.isLooping = true
|
rt.isLooping = true
|
||||||
rt!!.play()
|
rt.play()
|
||||||
} else {
|
} else {
|
||||||
rt!!.play()
|
rt.play()
|
||||||
rtTimer = Timer()
|
rtTimer = Timer()
|
||||||
rtTimer!!.scheduleAtFixedRate(object : TimerTask() {
|
rtTimer!!.scheduleAtFixedRate(object : TimerTask() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
if (rt != null && !rt!!.isPlaying) {
|
if (!rt.isPlaying)
|
||||||
rt!!.play()
|
rt.play()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, 1000, 1000)
|
}, 1000, 1000)
|
||||||
}
|
}
|
||||||
@ -1264,10 +1260,7 @@ class BaresipService: Service() {
|
|||||||
rtTimer!!.cancel()
|
rtTimer!!.cancel()
|
||||||
rtTimer = null
|
rtTimer = null
|
||||||
}
|
}
|
||||||
if (rt != null) {
|
rt.stop()
|
||||||
rt!!.stop()
|
|
||||||
rt = null
|
|
||||||
}
|
|
||||||
if (vbTimer != null) {
|
if (vbTimer != null) {
|
||||||
vbTimer!!.cancel()
|
vbTimer!!.cancel()
|
||||||
vbTimer = null
|
vbTimer = null
|
||||||
|
|||||||
Reference in New Issue
Block a user