Lessons · Building apps · 23 of 36
Sound and video
play, loop, stop_sounds, audio and video.
main player:
arrange: center
space_between: 12
children:
jingle:
button: "Play a sound"
on_tap: play(@ding.mp3)
music:
button: "Music on (loops)"
on_tap: play(@music.mp3, loop)
quiet:
button: "Stop all sounds"
on_tap: stop(sounds)
clip:
size: max, auto
video: @intro.mp4
loop: true
volume: 80
controls:
arrange: row
space_between: 8
children:
go:
button: "Play"
on_tap: play(clip)
hold:
button: "Pause"
on_tap: pause(clip)
back:
button: "Stop"
on_tap: stop(clip)
play(@x.mp3)plays a sound once; addloopto repeat it.stop(sounds)stops them all.- Vi draws no player.
video:shows only the frames andaudio:shows nothing; you make the buttons and callplay(box),pause(box)andstop(box)(stop goes back to the start). loop: truestarts it again when it ends;volume:goes from 0 (silent) to 100 (full).- Put the files in the
assetsfolder and write them with@. Web addresses go in quotes.
Every example here runs in Vi Studio: open it in your browser (phones too) and press Start learning on the welcome page. Each code block there has a Try it button that runs it in the phone preview.
More in Building apps
- Screensgo_to, go_back, transitions, and phone / tablet / desktop.
- Containers that take valuescard(task): one container, many values.
- Repeating thingsrepeat: task in tasks, grids, index, x, y and .at().
- Reaching other containersInside names, parent.name and top-level names.
- Changing the screenA dot for one change, a block for several; wait and animate.
- Timers and gamesevery(), stop(), on_touch, place: x, y and on_hit.
- Files and projectssrc/, every file sees every name, one name in one file.
- The config blockApp name, store id, version, icon and splash screen.
- Errors and good habitsThe real error messages and their fixes; how to organise a project.
About Vi. Vi is a free, open-source programming language for building real mobile apps. You describe each screen in plain words, and Vi compiles it to React Native (Expo) for Android, iOS and the web. Its editor, Vi Studio, runs on Windows, in any browser and on your phone, with the app running live as you type. Read more about Vi.