Closing devices
| Using playback and capture modes and devices |

### Closing devices

To close the capture and playback devices for a given server connection handler:

`unsigned int ts3client_closeCaptureDevice(` | serverConnectionHandlerID`)`; |

`uint64 serverConnectionHandlerID`;

`unsigned int ts3client_closePlaybackDevice(` | serverConnectionHandlerID`)`; |

`uint64 serverConnectionHandlerID`;

Parameters

- `serverConnectionHandlerID`

  ID of the server connection handler for which the playback or capture device should be closed.

Returns `ERROR_ok` on success, otherwise an error code as defined in `public_errors.h`.

`ts3client_closePlaybackDevice` will not block until all current sounds have finished playing but will shutdown the device immediately, possibly interrupting the still playing sounds. To shutdown the playback device more gracefully, use the following function:

`unsigned int ts3client_initiateGracefulPlaybackShutdown(` | serverConnectionHandlerID`)`; |

`uint64 serverConnectionHandlerID`;

Parameters

- `serverConnectionHandlerID`

  ID of the server connection handler for which the playback or capture device should be shut down.

Returns `ERROR_ok` on success, otherwise an error code as defined in `public_errors.h`.

While `ts3client_initiateGracefulPlaybackShutdown` will not block until all sounds have finished playing, too, it will notify the client when the playback device can be safely closed by sending the callback:

`void onPlaybackShutdownCompleteEvent(` | serverConnectionHandlerID`)`; |

`uint64 serverConnectionHandlerID`;

Parameters

- `serverConnectionHandlerID`

  ID of the server connection handler on which the playback device has been shut down.

Example code to gracefully shutdown the playback devicef:

    /* Instead of calling ts3client_closePlaybackDevice() directly */
    if(ts3client_initiateGracefulPlaybackShutdown(currentScHandlerID) != ERROR_ok) {
        printf("Failed to initiate graceful playback shutdown\n");
        return;
    }

    /* Event notifying the playback device has been shutdown */
    void my_onPlaybackShutdownCompleteEvent(uint64 scHandlerID) {
        /* Now we can safely close the device */
        if(ts3client_closePlaybackDevice(scHandlerID) != ERROR_ok) {
            printf("Error closing playback device\n");
        }
    }

| Note
Devices are closed automatically when calling `ts3client_destroyServerConnectionHandler`.

| Note
To change a device, close it first and then reopen it.

Checking current modes and devices |  | Using custom devices