*** id: 31534f2e-d5c3-4cac-88d4-356273171e16 title: Relay.Calling.PlayAction slug: /php/reference/calling/actions/play description: The PlayAction object is returned when playing audio. max-toc-depth: 3 ---------------- [relay-calling-playpauseresult]: /docs/server-sdk/v2/php/reference/calling/results/play-pause [relay-calling-playresult]: /docs/server-sdk/v2/php/reference/calling/results/play [relay-calling-playresumeresult]: /docs/server-sdk/v2/php/reference/calling/results/play-resume [relay-calling-playvolumeresult]: /docs/server-sdk/v2/php/reference/calling/results/play-volume [relay-calling-stopresult]: /docs/server-sdk/v2/php/reference/calling/results/stop [relay-consumer]: /docs/server-sdk/v2/php/reference/consumer This object returned from one of *asynchronous* play methods that represents a playing currently active on a call. ## Methods ### getControlId Return the UUID to identify the playing. **Parameters** *None* **Returns** `string` - UUID to identify the action. **Examples** Start the play and print the controlId. ```php playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')->done(function($action) { echo $action->getControlId(); }); ``` ### getPayload Return the payload sent to Relay to initiate the request. Useful to inspect what you sent to perform this action. **Parameters** *None* **Returns** `Object` - Payload sent to Relay. **Examples** Start the play and print out the payload. ```php playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')->done(function($action) { print_r($action->getPayload()); }); ``` ### getResult Returns the final result of the playing. **Parameters** *None* **Returns** [`Relay.Calling.PlayResult`][relay-calling-playresult] - Final result of the playing. **Examples** Start the play and grab the result when it's completed. ```php playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')->done(function($action) { // .. later in the code since it's an async method if ($action->isCompleted()) { $result = $action->getResult(); } }); ``` ### 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. ```php playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')->done(function($action) { echo $action->getState(); }); ``` ### isCompleted 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. ```php playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')->done(function($action) { if ($action->isCompleted()) { } }); ``` ### pause Pause the playback immediately. **Parameters** *None* **Returns** `React\Promise\Promise` - Promise object that will be fulfilled with a [`Relay.Calling.PlayPauseResult`][relay-calling-playpauseresult] object. **Examples** Start playing an audio file and pause it. ```php playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')->done(function($action) { // For demonstration purposes only.. $action->pause()->done(function($pauseResult) { if ($pauseResult->successful) { } }); }); ``` ### resume Resume the playback immediately. **Parameters** *None* **Returns** `React\Promise\Promise` - Promise object that will be fulfilled with a [`Relay.Calling.PlayResumeResult`][relay-calling-playresumeresult] object. **Examples** Start playing an audio file, stop it and then resume it. ```php playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')->done(function($action) { // For demonstration purposes only.. $action->pause()->done(function($pauseResult) use ($action) { // .. later in the code.. $action->resume()->done(function($resumeResult) { }); }); }); ``` > Note: you can avoid the *callback hell* using these methods in a [`Relay.Consumer`][relay-consumer]. ### stop Stop the action immediately. **Parameters** *None* **Returns** `React\Promise\Promise` - Promise object that will be fulfilled with a [`Relay.Calling.StopResult`][relay-calling-stopresult] object. **Examples** Start the play and stop it if an `Agent` is not available. ```php playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')->done(function($action) use ($globalAgent) { if ($globalAgent->isAvailable() === false) { $action->stop()->done(function($stopResult) { }); } }); ``` ### volume Control the volume of the playback. **Parameters** | Parameter | Type | Required | Description | | --------- | -------- | ------------ | ---------------------------------------------------------- | | `volume` | `number` | **required** | Volume value between -40dB and +40dB where 0 is unchanged. | **Returns** `React\Promise\Promise` - Promise object that will be fulfilled with a [`Relay.Calling.PlayVolumeResult`][relay-calling-playvolumeresult] object. **Examples** Start the play and increase the playback volume. ```php playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')->done(function($action) { // For demonstration purposes only.. $action->volume(5.0)->done(function($volumeResult) { if ($volumeResult->successful) { } }); }); ```