Add volume, pan and spatial audio options for video playback

This commit is contained in:
Wojtek Figat
2024-05-10 13:54:52 +02:00
parent f0d143ecaa
commit 6b31d51e31
7 changed files with 171 additions and 11 deletions

View File

@@ -11,7 +11,6 @@
/// Video playback utility. Video content can be presented in UI (via VideoBrush), used in materials (via texture parameter bind) or used manually in shaders.
/// </summary>
API_CLASS(Attributes="ActorContextMenu(\"New/Visuals/Video Player\"), ActorToolbox(\"Visuals\")")
class FLAXENGINE_API VideoPlayer : public Actor
{
DECLARE_SCENE_OBJECT(VideoPlayer);
@@ -42,7 +41,8 @@ public:
private:
VideoBackendPlayer _player;
States _state = States::Stopped;
bool _loop = false;
bool _loop = false, _isSpatial = false;
float _volume = 1.0f, _pan = 0.0f, _minDistance = 1000.0f, _attenuation = 1.0f;
public:
~VideoPlayer();
@@ -68,7 +68,7 @@ public:
API_PROPERTY() void SetIsLooping(bool value);
/// <summary>
/// Determines whether the video clip should auto play on level start.
/// Determines whether the video clip should autoplay on level start.
/// </summary>
API_FIELD(Attributes="EditorOrder(30), DefaultValue(false), EditorDisplay(\"Video Player\", \"Play On Start\")")
bool PlayOnStart = false;
@@ -79,6 +79,76 @@ public:
API_FIELD(Attributes = "EditorOrder(35), DefaultValue(0.0f), Limit(0, float.MaxValue, 0.01f), EditorDisplay(\"Video Player\"), VisibleIf(nameof(PlayOnStart))")
float StartTime = 0.0f;
/// <summary>
/// If checked, video player us using spatialization to play 3d audio, otherwise will always play as 2d sound.
/// </summary>
API_PROPERTY(Attributes="EditorOrder(50), DefaultValue(false), EditorDisplay(\"Video Player\")")
FORCE_INLINE bool GetIsAudioSpatial() const
{
return _isSpatial;
}
/// <summary>
/// If checked, source can play spatial 3d audio (when audio clip supports it), otherwise will always play as 2d sound. At 0, no distance attenuation ever occurs.
/// </summary>
API_PROPERTY() void SetIsAudioSpatial(bool value);
/// <summary>
/// Gets the volume of the audio played from this video, in [0, 1] range.
/// </summary>
API_PROPERTY(Attributes="EditorOrder(100), DefaultValue(1.0f), Limit(0, 1, 0.01f), EditorDisplay(\"Video Player\")")
FORCE_INLINE float GetAudioVolume() const
{
return _volume;
}
/// <summary>
/// Sets the volume of the audio played from this video, in [0, 1] range.
/// </summary>
API_PROPERTY() void SetAudioVolume(float value);
/// <summary>
/// Gets the stereo pan of the played audio (-1 is left speaker, 1 is right speaker, 0 is balanced). The default is 1. Used by non-spatial audio only.
/// </summary>
API_PROPERTY(Attributes="EditorOrder(110), DefaultValue(0.0f), Limit(-1.0f, 1.0f), EditorDisplay(\"Video Player\"), VisibleIf(nameof(IsAudioSpatial), true)")
FORCE_INLINE float GetAudioPan() const
{
return _pan;
}
/// <summary>
/// Sets the stereo pan of the played audio (-1 is left speaker, 1 is right speaker, 0 is balanced). The default is 0. Used by non-spatial audio only.
/// </summary>
API_PROPERTY() void SetAudioPan(float value);
/// <summary>
/// Gets the minimum distance at which audio attenuation starts. When the listener is closer to the video player than this value, audio is heard at full volume. Once farther away the audio starts attenuating.
/// </summary>
API_PROPERTY(Attributes="EditorOrder(120), DefaultValue(1000.0f), Limit(0, float.MaxValue, 0.1f), EditorDisplay(\"Video Player\"), VisibleIf(nameof(IsAudioSpatial))")
FORCE_INLINE float GetAudioMinDistance() const
{
return _minDistance;
}
/// <summary>
/// Sets the minimum distance at which audio attenuation starts. When the listener is closer to the video player than this value, audio is heard at full volume. Once farther away the audio starts attenuating.
/// </summary>
API_PROPERTY() void SetAudioMinDistance(float value);
/// <summary>
/// Gets the attenuation that controls how quickly does audio volume drop off as the listener moves further from the video player.
/// </summary>
API_PROPERTY(Attributes="EditorOrder(130), DefaultValue(1.0f), Limit(0, float.MaxValue, 0.1f), EditorDisplay(\"Video Player\"), VisibleIf(nameof(IsAudioSpatial))")
FORCE_INLINE float GetAudioAttenuation() const
{
return _attenuation;
}
/// <summary>
/// Sets the attenuation that controls how quickly does audio volume drop off as the listener moves further from the video player. At 0, no distance attenuation ever occurs.
/// </summary>
API_PROPERTY() void SetAudioAttenuation(float value);
public:
/// <summary>
/// Starts playing the currently assigned video Url.