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
This commit is contained in:
@@ -9,6 +9,7 @@ import android.content.BroadcastReceiver
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
|
import android.media.MediaPlayer
|
||||||
import android.net.NetworkInfo
|
import android.net.NetworkInfo
|
||||||
import android.net.wifi.WifiManager
|
import android.net.wifi.WifiManager
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
@@ -23,7 +24,6 @@ import java.io.FileInputStream
|
|||||||
import java.io.ObjectInputStream
|
import java.io.ObjectInputStream
|
||||||
import android.support.v4.content.LocalBroadcastManager
|
import android.support.v4.content.LocalBroadcastManager
|
||||||
import android.media.RingtoneManager
|
import android.media.RingtoneManager
|
||||||
import android.media.Ringtone
|
|
||||||
|
|
||||||
class BaresipService: Service() {
|
class BaresipService: Service() {
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ class BaresipService: Service() {
|
|||||||
internal lateinit var nr: BroadcastReceiver
|
internal lateinit var nr: BroadcastReceiver
|
||||||
internal lateinit var wl: PowerManager.WakeLock
|
internal lateinit var wl: PowerManager.WakeLock
|
||||||
internal lateinit var fl: WifiManager.WifiLock
|
internal lateinit var fl: WifiManager.WifiLock
|
||||||
internal lateinit var rt: Ringtone
|
internal lateinit var mp: MediaPlayer
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
|
|
||||||
@@ -73,7 +73,8 @@ class BaresipService: Service() {
|
|||||||
|
|
||||||
val uri = RingtoneManager
|
val uri = RingtoneManager
|
||||||
.getActualDefaultRingtoneUri(applicationContext, RingtoneManager.TYPE_RINGTONE)
|
.getActualDefaultRingtoneUri(applicationContext, RingtoneManager.TYPE_RINGTONE)
|
||||||
rt = RingtoneManager.getRingtone(applicationContext, uri)
|
mp = MediaPlayer.create(getApplicationContext(), uri)
|
||||||
|
mp.isLooping = true
|
||||||
|
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
}
|
}
|
||||||
@@ -252,7 +253,7 @@ class BaresipService: Service() {
|
|||||||
snb.setContent(view)
|
snb.setContent(view)
|
||||||
nm.notify(STATUS_NOTIFICATION_ID, snb.build())
|
nm.notify(STATUS_NOTIFICATION_ID, snb.build())
|
||||||
}
|
}
|
||||||
rt.play()
|
mp.start()
|
||||||
/* if (!Utils.isVisible()) {
|
/* if (!Utils.isVisible()) {
|
||||||
nm.cancel(STATUS_NOTIFICATION_ID)
|
nm.cancel(STATUS_NOTIFICATION_ID)
|
||||||
val cnb = NotificationCompat.Builder(this)
|
val cnb = NotificationCompat.Builder(this)
|
||||||
@@ -294,7 +295,7 @@ class BaresipService: Service() {
|
|||||||
snb.setContent(view)
|
snb.setContent(view)
|
||||||
snb.setVibrate(null)
|
snb.setVibrate(null)
|
||||||
nm.notify(STATUS_NOTIFICATION_ID, snb.build())
|
nm.notify(STATUS_NOTIFICATION_ID, snb.build())
|
||||||
rt.stop()
|
mp.stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -347,7 +348,7 @@ class BaresipService: Service() {
|
|||||||
val STATUS_NOTIFICATION_ID = 101
|
val STATUS_NOTIFICATION_ID = 101
|
||||||
val CALL_NOTIFICATION_ID = 102
|
val CALL_NOTIFICATION_ID = 102
|
||||||
var disconnected = false
|
var disconnected = false
|
||||||
val RUN_FOREGROUNG = true
|
val RUN_FOREGROUNG = false
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user