Loading...
Searching...
No Matches
PlaybackDevice.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#pragma once
26
28// Headers
30#include <SFML/Audio/Export.hpp>
31
32#include <functional>
33#include <optional>
34#include <string>
35#include <vector>
36
37#include <cstdint>
38
39
41{
71[[nodiscard]] SFML_AUDIO_API std::vector<std::string> getAvailableDevices();
72
88[[nodiscard]] SFML_AUDIO_API std::optional<std::string> getDefaultDevice();
89
108[[nodiscard]] SFML_AUDIO_API bool setDevice(const std::string& name);
109
148
170[[nodiscard]] SFML_AUDIO_API bool setDeviceToNull();
171
178[[nodiscard]] SFML_AUDIO_API std::optional<std::string> getDevice();
179
186[[nodiscard]] SFML_AUDIO_API std::optional<std::uint32_t> getDeviceSampleRate();
187
197[[nodiscard]] SFML_AUDIO_API bool isDefaultDevice();
198
212
217using NotificationCallback = std::function<void(Notification notification)>;
218
238
239} // namespace sf::PlaybackDevice
#define SFML_AUDIO_API
std::optional< std::string > getDefaultDevice()
Get the name of the default audio playback device.
bool isDefaultDevice()
Check if the current playback device is the default device.
Notification
Enumeration of the playback device notifications.
@ DeviceInterruptionEnded
Playback device interruption has ended (Generated on Apple mobile platforms).
@ DeviceStopped
Playback device has been stopped.
@ DeviceInterruptionBegan
Playback device interruption has begun (Generated on Apple mobile platforms).
@ DeviceRerouted
Playback device has been rerouted (Generated on platforms that support automatic stream routing).
@ DeviceUnlocked
Playback device has been unlocked (Generated by Emscripten/WebAudio).
@ DeviceStarted
Playback device has been started.
bool setDevice(const std::string &name)
Set the audio playback device.
std::function< void(Notification notification)> NotificationCallback
Callable that is called to notify of changes to the playback device state.
bool setDeviceToNull()
Set the audio playback device to the null device.
std::optional< std::string > getDevice()
Get the name of the current audio playback device.
std::optional< std::uint32_t > getDeviceSampleRate()
Get the sample rate of the current audio playback device.
void setNotificationCallback(NotificationCallback callback)
Set a callback that should be called to notify of changes to the playback device state.
std::vector< std::string > getAvailableDevices()
Get a list of the names of all available audio playback devices.
bool setDeviceToDefault()
Set the audio playback device to the default.