From db6897c6adf7c4c14c1841b3064f9874be1c02c9 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Sat, 30 Jun 2018 08:45:55 +0300 Subject: [PATCH] use mediaplayer instead of ringtone to play ring tone, since ringtone cannot be looped before api 26 by default, run baresip service in the background, since foreground on some devices used too much battery --- .../kotlin/com/tutpro/baresip/BaresipService.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 2593c675..8c9945ed 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -9,6 +9,7 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter +import android.media.MediaPlayer import android.net.NetworkInfo import android.net.wifi.WifiManager import android.os.IBinder @@ -23,7 +24,6 @@ import java.io.FileInputStream import java.io.ObjectInputStream import android.support.v4.content.LocalBroadcastManager import android.media.RingtoneManager -import android.media.Ringtone class BaresipService: Service() { @@ -37,7 +37,7 @@ class BaresipService: Service() { internal lateinit var nr: BroadcastReceiver internal lateinit var wl: PowerManager.WakeLock internal lateinit var fl: WifiManager.WifiLock - internal lateinit var rt: Ringtone + internal lateinit var mp: MediaPlayer override fun onCreate() { @@ -73,7 +73,8 @@ class BaresipService: Service() { val uri = RingtoneManager .getActualDefaultRingtoneUri(applicationContext, RingtoneManager.TYPE_RINGTONE) - rt = RingtoneManager.getRingtone(applicationContext, uri) + mp = MediaPlayer.create(getApplicationContext(), uri) + mp.isLooping = true super.onCreate() } @@ -252,7 +253,7 @@ class BaresipService: Service() { snb.setContent(view) nm.notify(STATUS_NOTIFICATION_ID, snb.build()) } - rt.play() + mp.start() /* if (!Utils.isVisible()) { nm.cancel(STATUS_NOTIFICATION_ID) val cnb = NotificationCompat.Builder(this) @@ -294,7 +295,7 @@ class BaresipService: Service() { snb.setContent(view) snb.setVibrate(null) nm.notify(STATUS_NOTIFICATION_ID, snb.build()) - rt.stop() + mp.stop() } } } @@ -347,7 +348,7 @@ class BaresipService: Service() { val STATUS_NOTIFICATION_ID = 101 val CALL_NOTIFICATION_ID = 102 var disconnected = false - val RUN_FOREGROUNG = true + val RUN_FOREGROUNG = false }