Why use Media Utils?
Playing a video in Scratch is impossible. If you want to make an interactive animation or AVG in Scratch, it is also an almost impossible mission. So we built Gandi Media Utilities not only to solve these problems but also to provide a simple audio engine with lazy-load features built in. With Gandi Media Utils, you can:
- use a video as a sprite
- lazy-load audio or video and control its playback (reduce first load file size)
- apply some audio effects to each channel (LPF, reverb, delay)
- (planned) play music with a sampler or a digital audio instrument
[ will be attached very soon ]
The extension contains four modules for now. A new digital audio instrument module will be added in the future.
Load and manage audio and video resources
Everything about video playback
Everything about lazy-load audio playback
🎛 Audio FX
A simple audio engine with which you can apply audio effects to each channel
(planned) Everything about digital audio instruments, including samplers, synthesizers, operators, and more
Functions and Definitions
Reload resource list
This button will be placed on the first item in the resource. If you uploaded a video or audio to the Cloud Library, tap Reload lazy audios/videos, and the list will be synced with the cloud library.
Lazy load video or audio
Load a video or audio and assign a name to it in this project.
Events when loaded
When a video or audio resource is loaded, the event will be dispatched.
Dispose of resources
If the resource is not used, you can dispose of it to reduce memory usage.
In this case, a video or audio named ‘bgm’ will be unloaded.
Check the status of resources in the project
Sometimes your project needs to load more than one resource at the same time. You can use this block to check the loading status.
Loading status of a video resource
In this case, this block returns true if the video named ‘thinkDifferent’ is not loaded.
Properties of a video resource
You can get these properties:
The current volume of the video resource. The loudness is measured in decibels (dB)
The current time in seconds
The duration of the video
The width of the original video
The height of the original video
When a video event is received
Possible events while a video is playing include:
Normally, will be dispatched when a video is loaded.
Will be dispatched while loading.
Will be dispatched while playing.
Will be displaced when a video reached the end.
Play and Pause
Will be dispatched when playing/pausing the video playback
Will be dispatched when an error is encountered
Play a video
Play a video at a particular start time. You can choose to loop or stop the playback when the video reaches the end.
Stop a video
You can choose whether to pause or to stop and remove the video.
When a video is removed, you won’t be able to play it again unless it is reloaded.
Draw a video on a sprite
Draw a video on a sprite layer. You should note:
i: x and y are not the positions of the video. They are the offset of the video. For example: You draw a video called thinkDifferent on the current sprite with an offset x: 10, y: 20. The current sprite's position is x: 5, y:6. The video will be placed on x: 10+5, y: 6+20.
ii: The scale of the sprite will affect the video too.
iii: If you leave the width and height options empty, the video will be drawn with its original size.
iv: If you leave the height option empty, the height will be calculated automatically based on the given width and the original video's aspect.
v: If you leave the width option empty, the width will be calculated based on the given height and the original video’s aspect.
iv and v are very useful. NEVER CHANGE THE ASPECT OF AN IMAGE OR A VIDEO is a good rule of thumb for a fine design. My most used code snippet is this:
Set a volume
0 dB represents setting volume to 100%. -3dB = 50%, -6dB = 25%, -96dB essentially equals 0%, 3dB = 200%.
Status of an audio
You can get these statuses:
- is not loaded?
- is loaded?
- is playing?
- is paused?
- is ended?
When status is changed
You can listen to the statuses play, end, pause, and resume.
Play an audio
Play audio at a start time. When reached the end, loop or stop the audio.
Pause/Resume/Remove an audio
The property of an audio
The current volume of the audio resource. The loudness is measured in decibels (dB)
The current time in seconds
The duration of the audio
Change the volume
Ramp volume of the audio to a destination volume at a specific time. This is very useful to fade in or out audio.
🎛 Audio FX
You can choose which channel to apply audio effects to.
- Master: all audios in the project will be connected to the master channel;
- Media Util: all lazy-load video and audio will be connected to it;
- Scratch: all sound blocks from Scratch.
All available FX
Lowpass Filter (LPF)
LPF is the most useful filter in DJing and audio processing. A cut frequency (in Hz) should be set while using LPF. Set it to 44100 to disable LPF. If you want to emulate a crazy neighbor playing music at midnight, try setting it to 800.
Disable: 44100 Keep a distance: 10000 In the bathroom of your crazy neighbor: 1000 In your bedroom but can hear the sound of a crazy neighbor: 400 It drives you crazy and you put a pillow over your head: 100
Reverb can be used to emulate spaces of different sizes. It is the effect of many echoes occurring simultaneously.
Bedroom: 1 Bathroom: 10 Church: 40
Delay is another type of audio effect that falls under the Time-based category. It is similar to Reverb, but the sound's reflection is clearer.
Normal room: delay 0.1, feedback 0.4 In a valley: delay 0.4, feedback 0.1
The loudness of the sound.
100% : 0 dB 50%: -3 dB 25%: -6 dB 200%: 3 dB
The balance of the audio (left or right) [-1,1]
Only left: -1 Only right: 1 Balanced: 0
We are planning to bring audio instruments, including samplers and synthesizers, to Scratch. Currently, you can play with the following experimental synthesizer:
Roadmap and Change Logs
Fixed: - Audio FX won’t affect audio from Scratch - Incorrect video positions Added: - Simple Audio Engine with audio FX and audio instruments - Unlimited tracks of video playback - New resource management
Init launch - Lazy-load audio playback - Two tracks videos playback