After a more detailed analysis, I discovered that the problem is not with the Background application.
Problem occurs immediately after the channel leaves the ConfBridge, at that moment you begin to hear white noise at the other end of the call. If you try to run the background application just after the channel leaves the Confbridge, the audio does not starts hearing until the end of that noise.
The duration of the noise is approximately 10 seconds and its volume decreases progressively.
Asterisk version: 13.18.3
Steps to reproduce:
//We have a ConfBridge (id 107) created previously for a call to an Asterisk extension (107), channel is: SIP/107-0000001f
11:23:14.905 Executing AGI Command: EXEC ConfBridge 107,default_bridge,regular_user
11:23:14.949 AGI Command ConfBridge, IdPetición: 1, Response:Success Message:Added AGI command to queue
// Channel joined the conference
11:23:14.954 ConfbridgeJoin_Event. Channel: SIP/107-0000001f, ConferenceId: 107
// An incoming call is received and we want connect that channel with the existing conference using ConfBridge. So we need starts an AGI session for the channel
// Channel starts AGI Session: SIP/ADL8256-00000022
11:27:40.063 AsyncAgiStart_Event. . Channel: SIP/ADL8256-00000022, UniqueId: 1515493526.438
11:27:40.063 AGI Session stated. Channel: CanalSIP/ADL8256-00000022
// In AGI Session, app executes AGI Command ConfBridge
11:27:40.063 Executing AGI Command: EXEC ConfBridge 107,default_bridge,regular_user
11:27:40.080 AGI Command ConfBridge, IdPetición: 11, Response:Success Message:Added AGI command to queue
// Channel joined the conference. Caller can talk to the person in the extension
11:27:40.082 ConfbridgeJoin_Event. Channel: SIP/ADL8256-00000022, ConferenceId: 107
// In AGI Session, app executes ConfBridgeKick
11:27:42.256 ConfbridgeKick Channel: SIP/ADL8256-00000022, Conference: 107. Response:Success Message:User kicked
// Channel leaves the conference. Noise is hearing in the caller phone (the other end of the call)
11:27:42.308 ConfbridgeLeave_Event. Channel: SIP/ADL8256-00000022, ConferenceId: 107
// We want to play some messages to the caller, so we need execute Background AGI Command
11:27:42.410 AGI Command Background, IdPetición: 12, Channel: SIP/ADL8256-00000022, Response:Success Message:Added AGI command to queue
// We receive AGIExecStart event for the background command. No sound, only noise for 10 seconds
11:27:42.461 AGIExecStart event. Command: EXEC Background tiphone/MusicaEspera_es, Channel: SIP/ADL8256-00000022
// 10 seconds after, tiphone/MusicaEspera_es starts
11:27:52.254 10 seconds after, caller starts to hear our sound file
Asterisk full log for the case: (Asterisk time is different that App time)
[2018-01-09 11:25:43] VERBOSE[20517][C-00000022] pbx.c: Executing [0@queues-agi:2] AGI(“SIP/ADL8256-00000022”, “agi:async”) in new stack
[2018-01-09 11:25:43] VERBOSE[20517][C-00000022] res_agi.c: AGI Script Executing Application: (ConfBridge) Options: (107,default_bridge,regular_user)
[2018-01-09 11:25:43] VERBOSE[20517][C-00000022] bridge_channel.c: Channel SIP/ADL8256-00000022 joined ‘softmix’ base-bridge
[2018-01-09 11:25:43] VERBOSE[20517][C-00000022] bridge_channel.c: Channel SIP/ADL8256-00000022 joined ‘softmix’ base-bridge
[2018-01-09 11:25:45] VERBOSE[20517][C-00000022] bridge_channel.c: Channel SIP/ADL8256-00000022 left ‘softmix’ base-bridge
[2018-01-09 11:25:45] VERBOSE[20517][C-00000022] pbx.c: Spawn extension (salir-agi, 0, 1) exited non-zero on ‘SIP/ADL8256-00000022’
[2018-01-09 11:25:45] VERBOSE[20517][C-00000022] pbx.c: Executing [0@salir-agi:1] AGI(“SIP/ADL8256-00000022”, “agi:async”) in new stack
[2018-01-09 11:25:45] VERBOSE[20517][C-00000022] res_agi.c: AGI Script Executing Application: (Background) Options: (tiphone/MusicaEspera_es)
[2018-01-09 11:25:45] VERBOSE[20517][C-00000022] file.c: <SIP/ADL8256-00000022> Playing ‘tiphone/MusicaEspera_es.slin’ (language ‘en’)
[2018-01-09 11:25:55] VERBOSE[20517][C-00000022] pbx.c: Spawn extension (stop-play, 0, 1) exited non-zero on ‘SIP/ADL8256-00000022’