Skip to main content

PlayAction

Relay.Calling.PlayAction

This object returned from one of asynchronous play methods that represents a playing currently active on a call.

Methods-submenu

GetResult

Returns the final result of the playing.

Parameters

None

Returns

Relay.Calling.PlayResult - Final result of the playing.

Examples

Start the play and grab the result when it's completed.

// MyOnPlayFinished ran when Play Action finishes
func MyOnPlayFinished(playAction *signalwire.PlayAction) {
result := playAction.GetResult()
if result.Successful {
signalwire.Log.Info("Play was successful\n")
}
}

resultDial.Call.OnPlayFinished = MyOnPlayFinished
playAction, err := resultDial.Call.PlayAudioAsync("https://cdn.signalwire.com/default-music/welcome.mp3")
if err != nil {
signalwire.Log.Error("Error occurred while trying to play audio\n")
}

GetState

Return the current state of the playing.

Parameters

None

Returns

string - Current state of the playing.

Examples

Start the play and print the state.

playAction, err := resultDial.Call.PlayAudioAsync("https://cdn.signalwire.com/default-music/welcome.mp3")
if err != nil {
signalwire.Log.Error("Error occurred while trying to play audio\n")
}

// [...]

if playAction.GetState() == signalwire.PlayPlaying {
signalwire.Log.Info("Audio is playing")
}

GetCompleted

Return true if the playing has finished, false otherwise.

Parameters

None

Returns

Boolean - True/False accordingly to the state.

Examples

Start the play and check if it has finished.

playAction, err := resultDial.Call.PlayAudioAsync("https://cdn.signalwire.com/default-music/welcome.mp3")
if err != nil {
signalwire.Log.Error("Error occurred while trying to Play audio\n")
}

for ok := true; ok; ok = !(playAction.GetCompleted()) {
time.Sleep(1 * time.Second)
}

GetControlID

Return the UUID to identify the action.

Parameters

None

Returns

string - UUID to identify the action.

Examples

Start a Play Action and print the controlId.

playAction, err := resultDial.Call.PlayAudioAsync("https://cdn.signalwire.com/default-music/welcome.mp3")
if err != nil {
signalwire.Log.Error("Error occurred while trying to Play audio\n")
}
Signalwire.Log.Info("Play Action ControlID: %s\n", playAction.GetControlID())

Stop

Stop the action immediately.

Parameters

None

Returns

Examples

Start the play and stop it.

playAction, err := resultDial.Call.PlayAudioAsync("https://cdn.signalwire.com/default-music/welcome.mp3")
if err != nil {
signalwire.Log.Error("Error occurred while trying to play audio\n")
}
// do something here
playAction.Stop()