SFML - Simple and Fast Multimedia Library

SFML 3.1.0
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
40 namespace sf::PlaybackDevice
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
147[[nodiscard]] SFML_AUDIO_API bool setDeviceToDefault();
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
203 enum class Notification
204{
205 DeviceStarted,
206 DeviceStopped,
207 DeviceRerouted,
208 DeviceInterruptionBegan,
209 DeviceInterruptionEnded,
210 DeviceUnlocked
211};
212
217 using NotificationCallback = std::function<void(Notification notification)>;
218
237 SFML_AUDIO_API void setNotificationCallback(NotificationCallback callback);
238
239} // namespace sf::PlaybackDevice
Export.hpp
SFML_AUDIO_API
#define SFML_AUDIO_API
Definition Audio/Export.hpp:42
sf::PlaybackDevice
Definition PlaybackDevice.hpp:41
sf::PlaybackDevice::getDefaultDevice
std::optional< std::string > getDefaultDevice()
Get the name of the default audio playback device.
sf::PlaybackDevice::isDefaultDevice
bool isDefaultDevice()
Check if the current playback device is the default device.
sf::PlaybackDevice::Notification
Notification
Enumeration of the playback device notifications.
Definition PlaybackDevice.hpp:204
sf::PlaybackDevice::Notification::DeviceInterruptionEnded
@ DeviceInterruptionEnded
Playback device interruption has ended (Generated on Apple mobile platforms).
Definition PlaybackDevice.hpp:209
sf::PlaybackDevice::Notification::DeviceStopped
@ DeviceStopped
Playback device has been stopped.
Definition PlaybackDevice.hpp:206
sf::PlaybackDevice::Notification::DeviceInterruptionBegan
@ DeviceInterruptionBegan
Playback device interruption has begun (Generated on Apple mobile platforms).
Definition PlaybackDevice.hpp:208
sf::PlaybackDevice::Notification::DeviceRerouted
@ DeviceRerouted
Playback device has been rerouted (Generated on platforms that support automatic stream routing).
Definition PlaybackDevice.hpp:207
sf::PlaybackDevice::Notification::DeviceUnlocked
@ DeviceUnlocked
Playback device has been unlocked (Generated by Emscripten/WebAudio).
Definition PlaybackDevice.hpp:210
sf::PlaybackDevice::Notification::DeviceStarted
@ DeviceStarted
Playback device has been started.
Definition PlaybackDevice.hpp:205
sf::PlaybackDevice::setDevice
bool setDevice(const std::string &name)
Set the audio playback device.
sf::PlaybackDevice::NotificationCallback
std::function< void(Notification notification)> NotificationCallback
Callable that is called to notify of changes to the playback device state.
Definition PlaybackDevice.hpp:217
sf::PlaybackDevice::setDeviceToNull
bool setDeviceToNull()
Set the audio playback device to the null device.
sf::PlaybackDevice::getDevice
std::optional< std::string > getDevice()
Get the name of the current audio playback device.
sf::PlaybackDevice::getDeviceSampleRate
std::optional< std::uint32_t > getDeviceSampleRate()
Get the sample rate of the current audio playback device.
sf::PlaybackDevice::setNotificationCallback
void setNotificationCallback(NotificationCallback callback)
Set a callback that should be called to notify of changes to the playback device state.
sf::PlaybackDevice::getAvailableDevices
std::vector< std::string > getAvailableDevices()
Get a list of the names of all available audio playback devices.
sf::PlaybackDevice::setDeviceToDefault
bool setDeviceToDefault()
Set the audio playback device to the default.