Expand-assets Class
These docs have moved here.Reference for DEVELOPERS of new frames only!
Mixin to allow users to provide audio/video and image source values as either relative paths
within a base directory or as full paths.
If using along with other mixins, this should be listed LAST to enable those mixins to add to the set
of assets that need to be expanded if needed.
When adding this mixin to a frame, you will need to define a property of the frame
assetsToExpand, which indicates which parameters might be source objects that need
expansion. assetsToExpand should be an object with keys image, video, and audio,
and each value should be an Array of parameter names that provide sources for resources
of the corresponding type. E.g.,
{
'image': ['leftObjectPic', 'rightObjectPic'],
'audio': ['introAudio', 'testAudio'],
'video': ['objectDemoVideo']
}
This is defined directly within your frame, e.g.:
export default ExpFrameBaseComponent.extend(ExpandAssets, {
...
type: 'exp-my-cool-frame',
assetsToExpand: {
'image': ['leftObjectPic', 'rightObjectPic'],
'audio': ['introAudio', 'testAudio'],
'video': ['objectDemoVideo']
},
...,
meta: {...},
actions: {...}
});
The user of your frame can then optionally provide baseDir, audioTypes, and
videoTypes parameters to indicate how to expand relative paths.
How expansion works:
- Images: Suppose the list
assetsToExpand['image']containscenterStimulus. IfcenterStimulusis provided as a full URL (with://in it), nothing will happen to it. But ifcenterStimulusis a string that is not a full URL, it will be transformed during thedidReceiveAttrshook tobaseDir + 'img/' + centerStimulus. - Audio: Suppose the list
assetsToExpand['audio']containsutterance1. Ifutterance1is a nonempty string (rather than an object/Array), e.g.,goodmorning, andaudioTypeshas been set to['typeA', 'typeB'], thenutterance1will be expanded out to
[
{
src: 'baseDir' + 'typeA/goodmorning.typeA',
type: 'audio/typeA'
},
{
src: 'baseDir' + 'typeB/goodmorning.typeB',
type: 'audio/typeB'
}
]
- Video: Same as audio, but using the types from
videoTypes. Important: During thedidReceiveAttrshook, your frame will acquire new properties[parameterName]_parsedfor each of the parameters named inassetsToExpand. These properties will hold the expanded values. E.g., in the example above, you would now have acenterStimulus_parsedproperty. This is what you should use for showing/playing images/audio/video in your frame template. Advanced use: the property names inassetsToExpandcan be either full parameter names as in the examples above, or can be of the formparameterName/subProperty. If using theparameterName/subPropertysyntax, instead of processing the parameterparameterName, we will expect that that parameter is either an object with propertysubProperty(which will be expanded) or an Array of objects with propertysubProperty(which will be expanded). The original value of theparameterNameparameter may in this case be mutated as assets are expanded. However, your frame will still also acquire a new property[parameterName]_parsedwhich you should use for accessing the processed values. This avoids potential problems with the template being rendered using the original values and not updated.
Item Index
Properties
Properties
audioTypes
String[]
List of audio types to expect for any audio specified just
with a string rather than with a list of src/type objects.
If audioTypes is ['typeA', 'typeB'] and an audio source
is given as intro, the audio source will be
expanded out to
[
{
src: 'baseDir' + 'typeA/intro.typeA',
type: 'audio/typeA'
},
{
src: 'baseDir' + 'typeB/intro.typeB',
type: 'audio/typeB'
}
]
Default: ['mp3', 'ogg']
baseDir
String
Base directory for where to find stimuli. Any image src
values that are not full paths will be expanded by prefixing
with baseDir + img/. Any audio/video src values provided as
strings rather than objects with src and type will be
expanded out to baseDir/avtype/[stub].avtype, where the potential
avtypes are given by audioTypes and videoTypes.
baseDir should include a trailing slash
(e.g., http://stimuli.org/myexperiment/); if a value is provided that
does not end in a slash, one will be added.
Default: ''
videoTypes
String[]
List of video types to expect for any audio specified just
with a string rather than with a list of src/type objects.
If videoTypes is ['typeA', 'typeB'] and a video source
is given as intro, the video source will be
expanded out to
[
{
src: 'baseDir' + 'typeA/intro.typeA',
type: 'video/typeA'
},
{
src: 'baseDir' + 'typeB/intro.typeB',
type: 'video/typeB'
}
]
Default: ['mp4', 'webm']