Version: 3.0.0
Audio
Description
The Audio component allows you to play audio resources and 3D sound effects. It supports spatialization and basic controls - such as stop and start - using WAV, MP3, and OGG format files. Loaded file and Streamed file audio components require an audio resource, which is the audio file you want to play.
Example
โ ๏ธ Don't forget to include the resources
in yourapp.package
file!
import React from "react";
import { View, Audio,Scene, Prism } from "magic-script-components";
export default class MyApp extends React.Component {
render() {
return (
<Prism size={[1.0, 1.0, 1.0]} >
<Scene>
<View name="main-view">
<Audio
fileName="resources/your-audio-file.mp3"
loadFile={true}
action="start"
/>
</View>
</Scene>
</Prism>
);
}
}
Common Events
Common Properties
Create Properties
Name | Type | Default Value | Required | Description | Lumin | Android | IOS |
---|---|---|---|---|---|---|---|
fileName | string | n/a | Y | File name of the resource to load. By default this is assumed to be a relative path from the executable file. | ๐ | ๐ | ๐ |
loadFile | boolean | false | N | Loads the entire audio file in the memory. For large files sizes you may use the createStreamedFileAudioResource method instead. | ๐ | ||
absolutePath | boolean | false | N | Flags that fileName as an absolute path name instead of a relative path. | ๐ | ||
descriptor | number | -1 | N | Optional file descriptor that points to a resource. | ๐ | ||
basePath | string | null | N | If you are loading a resource from an absolute path, and that path is not the current process path, set this field to the equivalent base path in the other client directory. This allows path relative dependencies to solve a fully qualified (absolute) path outside of the current process. This value defaults to the currently executing process root. | ๐ | ||
autoDestroy | boolean | false | N | If true , play the sound once and delete the node. If false the audio node will stay until the scenegraph is destroyed. | ๐ | ||
dynamicDecode | boolean | false | N | If true , the file resource is compressed and is decoded when playing. If false , the file resource is uncompressed PCM data. | ๐ |
Element Properties
Name | Type | Default Value | Description | Lumin | Android | IOS |
---|---|---|---|---|---|---|
action | string | n/a | Sets the current operation: start , stop , pause , resume | ๐ | ๐ | ๐ |
soundLooping | boolean | false | Sets audio playback to repeat mode. If enabled, audio plays from the start after reaching the end until disabled. When audio is created this is disabled by default. | ๐ | ๐ | ๐ |
soundMute | boolean | false | Mutes or unmutes the sound. | ๐ | ๐ | ๐ |
soundPitch | number | 1.0 | Sets the sound pitch. The range of the pitch is 0.5 to 2.0, with 0.5 being one octave down and 2.0 being one octave up. | ๐ | ||
soundVolumeLinear | number | n/a | Sets the audio volume. The range of the volume is 0 to 8, with 0 for silence, 1 for unity gain, and 8 for 8x gain. | ๐ | ๐ | ๐ |
spatialSoundEnable | boolean | false | Enables or disables the capability for spatial sound. If enabled, spatialSoundPosition must have a value for positional sound to be effective. | ๐ | ๐ | ๐ |
streamedFileOffset | number | n/a | Sets the starting point for playback of a streamed-file sound. | ๐ | ||
spatialSoundDirection | object | n/a | Sets the sound direction of a given audio channel. This is effective only if spatial sound is enabled (spatialSoundEnable ) for an audio node. The direction is relative to the node's local orientation. By default the direction is the same as the parent node's orientation. If the audio file is already playing, the direction changes during playback when the sound direction is set. | ๐ | ๐ | ๐ |
spatialSoundDirectSendLevels | object | n/a | Sets the direct send levels for one channel of a sound output. When 3D audio processing is enabled for a sound output (spatialSoundEnabled ) this property sets the send levels for the direct component of the sound, i.e., the audio mix for the part of the sound not affected by room acoustics. Multi-channel sounds require the direct send levels to be set individually for each channel by calling this function once for each channel. For mono sounds use channel = 0 . For stereo sounds use channel = 0 for left and channel = 1 for right. | ๐ | ||
spatialSoundDistance | object | n/a | Sets spatial sound distance parameters for a given channel. | ๐ | ๐ | ๐ |
spatialSoundPosition | object | n/a | Sets the position of a given audio channel relative to the node's local position. This is effective only if spatial sound is enabled (spatialSoundEnable ) for an audio node. This changes the position even if the audio clip is already playing. | ๐ | ๐ | ๐ |
spatialSoundRadiation | object | n/a | Sets spatial sound radiation parameters for a given channel. | ๐ | ||
spatialSoundRoomSendLevels | object | n/a | Sets the room send levels for one channel of a sound output. When 3D audio processing is enabled for a sound output (spatialSoundEnabled ) this function sets the send levels for the room component of the sound, i.e., the audio mix for the part of the sound that is affected by room acoustics. Multi-channel sounds require the room send levels to be set individually for each channel by calling this function once for each channel. For mono sounds use channel = 0 . For stereo sounds use channel = 0 for left and channel = 1 for right. | ๐ |
spatialSoundDirection
{
channel: number,
channelDirection: quat
}
spatialSoundDirectSendLevels
{
channel: number,
gain: number,
gainHf: number,
gainLf: number,
gainMf: number
}
spatialSoundDistance
{
channel: number,
minDistance: number,
maxDistance: number,
rolloffFactor: number
}
spatialSoundPosition
{
channel: number,
channelPosition: vec3
}
spatialSoundRadiation
{
channel: number,
innerAngle: number,
outerAngle: number,
outerGain: number,
outerGainHf: number
}
spatialSoundRoomSendLevels
{
channel: number,
gain: number,
gainHf: number,
gainLf: number,
gainMf: number
}