(TODO)Video Introduction
Video
There are 4 patterns to play a video file. Altenative to those video APIs, you may use spritesheet or sequential png files for animation though they don’t contain audio
Video/Animation Playback Methods Comparison
Method | Remote URL Support | Local File Support | Format | Features | Use Case |
---|---|---|---|---|---|
Native Play | ✅ | ✅ | MP4, MOV | MOV(iOS):Transparent background in iOS | Embedded videos with UI integration |
Media Play | ✅ | ✅ | MP4, MOV | Full screen playback, system controls | Simple full-screen video playback |
Web View | ✅ | ✅ | Any browser-supported format | Streaming services | YouTube or other streaming services |
Plugin Movie | ❌ | ✅ | OGV, OGG | Custom filters can be applied | integration with game objects |
Spritesheet | ❌ | ✅ | PNG | uniform, imagesheet | tools availlable like texturepacker, Adobe Animate |
PNG files | ❌ | ✅ | Sequentiap PNG files | ||
Plugin Extended Image | ❌ | ✅ | WebP | SVG/QOI are also supported in plugin_gfxe |
- TODO native play
https://kwiksher.com/doc/kwik_tutorial/media/video/#page1---native-play-video
App/videoBook/assets/videos/kwikplant_native
- TODO native play
- TODO media play full screen
- https://kwiksher.com/doc/kwik_tutorial/media/video/#page2---media-play-video
- App/videoBook/assets/videos/kwikplant_media
- TODO media play full screen
TODO web view
https://kwiksher.com/doc/kwik_tutorial/media/video/#page3---web-view
https://www.youtube.com/watch?v=fWd2ZHqnw80&feature=youtu.be
youtube.html is a static html with a youtbe url
create_webview.lua creates a webview from a youtube url
youtube streaming video can be played with web view(page3 method). The other three methods, Solar2D needs to load a video file either locally or from remort and play progressively downloading it.
TODO plugin movie - ogv
- sample_video.ogv
- loop_test_novideo.ogg
https://github.com/ANSH3LL/plugin_movie
ffmpeg -i video.mp4 -c:v libtheora -q:v 7 -c:a libvorbis -q:a 5 -pix_fmt yuv420p video.ogv
Alternatives by PNG file
Adobe Animate can produce .wav files along exporting PNG sequential files
Method | Format | Sample files | Benefits | Limitations |
---|---|---|---|---|
Spritesheets (Uniform) | PNG | sprites.png sprites@2x.png sprites@4x.png | Multiple resolution support Efficient memory usage | Simple |
Spritesheets (Adobe Animate) | JSON Array + PNG | Squirrel.json Squirrel.png | Adobe Animate as authoring images | Adobe Animate subscripton cost |
Spritesheets (Texture Packer) | LUA + PNG | uma.lua uma.png | Optimized texture layout | Image creation by other tools Requires Texture Packer |
Sequential PNG Files | PNG series | movieClip/001-035.png | Easy to create as many frames as in png | Many files to manage Higher memory usage |
PNG sequential examples in Video Replacement
movieClip/001- 035.png
https://kwiksher.com/blog/2019/08/28/character-animator-png-sequence/
spritehseets
- uniform-sized image
- sprites.png
- sprites@2x.png
- sprites@4x.png
- An/spritesheet(Adobe Animate JSON Array)
- Squirrel.json
- Squirrel.png
- image with sheetInfo (texture packer)
- uma.lua
- uma.png
- uniform-sized image
TODO about @2x, @4x for videos and spritesheets
Alternatives by WebP - plugin_gfxe
the plugin able to render qoi, svg and webp.
https://forums.solar2d.com/t/graphics-extensions-for-solar2d/354890
Format Description Animation Supported Notes SVG Scalable Vector Graphics, an XML-based vector image format. ❌ Primarily used for static vector graphics. Can include scripts for interactivity but not native animation. SVGZ Compressed version of SVG using gzip. ❌ Same as SVG but smaller in size due to compression. WebP A modern image format developed by Google, supporting both lossy and lossless compression. ✅ Supports animation (similar to GIF) and transparency. Widely used for web graphics. QOI Quite OK Image, a fast and simple lossless image format. ❌ Designed for static images with a focus on simplicity and speed.
Sample Project
The sample project: videoBook is here, and it contains two video files and two spritehseet files, and one sequentail png files
https://kwiksher.com/tutorials/Kwik5/VideoBook.zip
- App/videoBook/assets/sprites
- App/videoBook/assets/videos
- kwikplanet.mp4
- movie-hevc.mov (transparent background)
Navigaton
Create navigation is checked and the navigation panel will be displayed when the video finished on page4
by pressing Configure button, you will see
Pages
- Page1 - native play video
- Page2 - Media Play Video (full screen)
- Page 3 Web View
- page4 -when native play video completes , let’s show other images
Page1 - native play video
layer and replacements > Video for videoFrame. You can choose a video URL on the Internet or the local video file to be included in your app.
If the video file is included in App/book/assets/videos folder, set a path to the file.
Control buttons
- play, pause and rewind controls to each button
Page2 - media play video
External code is set to playBtn on page2. No layer relacment is used.
code > External Code.
Now set the following code - media_playvideo.lua
media_playvideo.lua
local onComplete = function( event )
print( "video session ended" )
end
local showControls = true
media.playVideo(
"http://kwiksher.com/tutorials/Video/kwikplanet.mp4",
media.RemoteSource, showControls, onComplete )
if you like to play the video included in assets/videos/ folder, please use this one
local onComplete = function( event )
print( "video session ended" )
end
local showControls = true
media.playVideo( "videos/kwikplanet.mp4", showControls, onComplete )
Page3 - Web View
Layer and Replacement to webFrame layer
In Web View Replacement Window, http://kwiksher.com/tutorials/Video/youtube.html is set. This html plays youtube video inline.
If you want to incude the html in the app, set the html file path. Kwik copies it and set it to build/ folder
Go to URL
To open browser app on device, use Go o URL in button’s interactions.
- Add Button > Web > Go to URL. https://www.youtube.com URL is set
Page4 Video Completion Action
when native play video ends, let’s trigger an action which contains linear animations and show/hide navigation.
- VideoFrame layer is the top over the the rocket icon, “to be continued” and the staticImage. When the video is finished, the videoFrame is hidden and the other layers are shown.
Create rocket rotation animation
- Rotation widget window.
- Starts: Wait request
staticImage Linear Animation.
Just tranparent 0% to 100% and Wait request.
Create an Action
this action will be triggered when Video is finished
- Show/Hide videoFrame
- Play Animation rocket rotation
- Play Animation staticImage from 0% to 100% alpha
- Show/Hide Navigation
Video Replacement with Action
- local kwikplanet.mp4 is set and Action is set wit the action created above.
Build for device
Preview with iPhone or iPad
Page1
Page2
Page3
Page4
Page4 finished
- TODO P.S. Android has an issue about making native video transparent. See the forum topic below. Need to work around by resize the video frame or moving it off the screen instead of hide function.
http://kwiksher.com/forums/topic/hide-video-in-android-device/
Solar2D Sample
Media
NewVideo
BigBuckBunny_640x360.m4v
video = native.newVideo( videoFrame.x, videoFrame.y, videoFrame.width, videoFrame.height ) video:load( "https://coronalabs.com/video/bbb/BigBuckBunny_640x360.m4v", media.RemoteSource ) video:addEventListener( "video", videoListener )
VideoPlayer
BigBuckBunny_640x360.m4v
media.playVideo( "https://coronalabs.com/video/bbb/BigBuckBunny_640x360.m4v", media.RemoteSource, true )
Animation
HorseAnimation
uma.png, uma.lua
local umaSheet = graphics.newImageSheet( "uma.png", options ) local spriteOptions = { name="uma", start=1, count=8, time=1000 } local spriteInstance = display.newSprite( sceneContainer, umaSheet, spriteOptions )
SpriteTiles
sprites.png sprites@2x.png sprites@4x.png
-- Create player sprite sheet local sheetOptions = { width = 50, height = 50, numFrames = 64, sheetContentWidth = 800, sheetContentHeight = 200 } local characterSheet = graphics.newImageSheet( "sprites.png", sheetOptions ) -- Create display group for sprites local group = display.newGroup() mainGroup:insert( group ) -- Calculate how many total rows and columns will fill screen local tilesPerRow = math.ceil( display.actualContentWidth / 60 ) local totalRows = math.ceil( (display.actualContentHeight-30) / 60 ) -- Generate sprites for i = 1,totalRows do for j = 1,tilesPerRow do local rnd = math.random( 1,16 ) local sequenceData = { name = "character", start = (rnd * 4) - 3, count = 4, time = 600 } local sprite = display.newSprite( group, characterSheet, sequenceData ) sprite.x = j * 60 sprite.y = i * 60 sprite:play() end end
–
Plugin movie
https://github.com/ANSH3LL/plugin_movie
av_sync_test.ogv
loop_test_nosound.ogv
loop_test_novideo.ogg
loop_test_sound.ogv sample_video.ogv
-- returns a texture object
movie.newMovieTexture{
filename = string, -- the video's filename [required]
baseDir = userdata, -- file's base directory, e.g: system.ResourceDirectory [optional]
channel = number -- audio channel to use [optional]
}
-- returns an imagerect
movie.newMovieRect{
x = number, -- [required]
y = number, -- [required]
width = number, -- [required]
height = number, -- [required]
filename = string, -- the video's filename [required]
baseDir = userdata, -- file's base directory, e.g: system.ResourceDirectory [optional]
channel = number, -- audio channel to use [optional]
listener = function -- callback function that will receive events from this object [optional]
}
-- returns a group with 2 imagerect objects named one and two
-- channel1 and channel2 MUST be different (especially if the video contains audio)
movie.newMovieLoop{
x = number, -- [required]
y = number, -- [required]
width = number, -- [required]
height = number, -- [required]
channel1 = number, -- audio channel used by imagerect one [required]
channel2 = number, -- audio channel used by imagerect two [required]
filename = string, -- the video's filename [required]
baseDir = userdata, -- file's base directory, e.g: system.ResourceDirectory [optional]
listener = function -- callback function that will receive events from this object [optional]
}