PlayAction

View as Markdown

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.

1// MyOnPlayFinished ran when Play Action finishes
2func MyOnPlayFinished(playAction *signalwire.PlayAction) {
3 result := playAction.GetResult()
4 if result.Successful {
5 signalwire.Log.Info("Play was successful\n")
6 }
7}
8
9resultDial.Call.OnPlayFinished = MyOnPlayFinished
10playAction, err := resultDial.Call.PlayAudioAsync("https://cdn.signalwire.com/default-music/welcome.mp3")
11if err != nil {
12 signalwire.Log.Error("Error occurred while trying to play audio\n")
13}

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.

1playAction, err := resultDial.Call.PlayAudioAsync("https://cdn.signalwire.com/default-music/welcome.mp3")
2if err != nil {
3 signalwire.Log.Error("Error occurred while trying to play audio\n")
4}
5
6// [...]
7
8if playAction.GetState() == signalwire.PlayPlaying {
9 signalwire.Log.Info("Audio is playing")
10}

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.

1playAction, err := resultDial.Call.PlayAudioAsync("https://cdn.signalwire.com/default-music/welcome.mp3")
2if err != nil {
3 signalwire.Log.Error("Error occurred while trying to Play audio\n")
4}
5
6for ok := true; ok; ok = !(playAction.GetCompleted()) {
7 time.Sleep(1 * time.Second)
8}

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.

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

Stop

Stop the action immediately.

Parameters

None

Returns

Examples

Start the play and stop it.

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