Pause audio file not play on receiver side in sip in android

45 Views Asked by At

I'm working on a project where I'm using the SIP (Linphone library). I'm facing an issue where, when the caller dials a call and the receiver accepts it, if a new call comes in on the caller side, the ongoing call gets paused (a pause event occurs in SIP onCallStateChanged). However, on the receiver side, the pause file is not played. Below, I'm sharing some of my code.

 private var callHandler: Core? = null    

fun init(
        context: Context,
        username: String,
        password: String,
        sipDomain: String,
        sipIp: String,
        sipPort: String
    ) {
    

        if (isRegister or isRegisterInProgress) {
      
            return
        }


     
        callHandler = factory.createCore(null, null, context)

        callHandler?.start()
        callHandler?.disableRecordOnMute = true
        callHandler?.playFile = getPauseFile(context)
        callHandler?.useFiles=false
        callHandler?.enableEchoCancellation(true)
        callHandler?.enableEchoLimiter(false)
        register(username, password, sipDomain, sipIp, sipPort)
    }



    private fun getPauseFile(context: Context):String{
        val mPauseFile="${context.filesDir.absolutePath}/play.wav"
        val lFileToCopy = File(mPauseFile)
        if (!lFileToCopy.exists()) {
            val lOutputStream: FileOutputStream = context.openFileOutput(lFileToCopy.name, 0)
            val lInputStream: InputStream = context.resources.openRawResource(R.raw.play)
            var readByte: Int
            val buff = ByteArray(8048)
            while (lInputStream.read(buff).also { readByte = it } != -1) {
                lOutputStream.write(buff, 0, readByte)
            }
            lOutputStream.flush()
            lOutputStream.close()
            lInputStream.close()
        }
        return mPauseFile
    }




    fun register(
        username: String,
        password: String,
        sipDomain: String,
        sipIp: String,
        sipPort: String
    ) {
        
        callHandler?.let { core ->
            val transportType = Constants.transportType
            val authInfo =
                factory.createAuthInfo(username, null, password, null, null, sipDomain, null)

            val params = core.createAccountParams()
            val identity = Factory.instance().createAddress("sip:$username@$sipDomain")
            params.identityAddress = identity

            val address = Factory.instance().createAddress("sip:$sipIp:$sipPort")
            address?.transport = transportType
            params.serverAddress = address
            if (!params.outboundProxyEnabled) {
                params.outboundProxyEnabled = true
            }
            params.registerEnabled = true
            val account = core.createAccount(params)

            core.addAuthInfo(authInfo)
            core.addAccount(account)

            // Asks the CaptureTextureView to resize to match the captured video's size ratio
            // core.config.setBool("video", "auto_resize_preview_to_keep_ratio", true)

            core.defaultAccount = account
            core.addListener(coreListener)


        } ?: return

    }

"I'm call init function from the main activity. Now, could you help me identify what might be wrong with the code provided above?"

How i play file on receiver side when caller gone pause state?

0

There are 0 best solutions below