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
Best Practices
[ will be attached very soon ]
Modules
The extension contains four modules for now. A new digital audio instrument module will be added in the future.
Module | Description |
💎 Resource | Load and manage audio and video resources |
🎬 Video | Everything about video playback |
🎹 Music | Everything about lazy-load audio playback |
🎛 Audio FX | A simple audio engine with which you can apply audio effects to each channel |
🔬 Experimental | (planned) Everything about digital audio instruments, including samplers, synthesizers, operators, and more |
Functions and Definitions
💎 Resource
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.
🎬 Video
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:
Property | Description | Example Value |
volume | The current volume of the video resource. The loudness is measured in decibels (dB) | 0 |
current time | The current time in seconds | 1.1 |
duration | The duration of the video | 62.5 |
width | The width of the original video | 1280 |
height | The height of the original video | 720 |
When a video event is received
Possible events while a video is playing include:
Event | Description |
Duration change | Normally, will be dispatched when a video is loaded. |
Progress | Will be dispatched while loading. |
Time update | Will be dispatched while playing. |
Ended | Will be displaced when a video reached the end. |
Play and Pause | Will be dispatched when playing/pausing the video playback |
Error | 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%.
🎹 Music
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
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
The blocks: