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
. IfcenterStimulus
is provided as a full URL (with://
in it), nothing will happen to it. But ifcenterStimulus
is a string that is not a full URL, it will be transformed during thedidReceiveAttrs
hook tobaseDir + 'img/' + centerStimulus
. - Audio: Suppose the list
assetsToExpand['audio']
containsutterance1
. Ifutterance1
is a nonempty string (rather than an object/Array), e.g.,goodmorning
, andaudioTypes
has been set to['typeA', 'typeB']
, thenutterance1
will 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 thedidReceiveAttrs
hook, your frame will acquire new properties[parameterName]_parsed
for each of the parameters named inassetsToExpand
. These properties will hold the expanded values. E.g., in the example above, you would now have acenterStimulus_parsed
property. This is what you should use for showing/playing images/audio/video in your frame template. Advanced use: the property names inassetsToExpand
can be either full parameter names as in the examples above, or can be of the formparameterName/subProperty
. If using theparameterName/subProperty
syntax, 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 theparameterName
parameter may in this case be mutated as assets are expanded. However, your frame will still also acquire a new property[parameterName]_parsed
which 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']