A video-to-texture plugin for the solar2D (formerly corona-sdk) game engine
- Plays
Ogg Theora
video files - Capable of playing videos in a loop
- Renders video to a
CoronaExternalTexture
that can be used to fill aShapeObject
,ImageRect
, etc - Automatically plays audio in synchronicity with video
Add the plugin to your build settings like so:
plugins = {
["plugin.movie"] = {
publisherId = "com.ansh3ll"
},
},
Simple usage example like so:
local movie = require('plugin.movie')
local function movieListener(event)
if event.phase == 'stopped' then
print('Video watched to end? ', event.completed)
end
--
for k, v in pairs(event) do
print(k .. ' = ' .. v)
end
end
local player = movie.newMovieRect(
{
x = display.contentCenterX,
y = display.contentCenterY,
width = 960,
height = 540,
channel = 3,
listener = movieListener,
filename = 'intro_cutscene.ogv'
}
)
audio.setVolume(1, {channel = player.channel})
player.play()
A more advanced usage example can be found in the Corona/
directory here
If you would like to take the DIY option and use a MovieTexture
to fill an object of your choice, take a look at the implementation of MovieRect
here
A texture object that can play a video
newMovieTexture
- loads a video file and returns aMovieTexture
movieTexture:play
- starts/resumes video playbackmovieTexture:pause
- pauses video playbackmovieTexture:stop
- stops video playbackmovieTexture:update
- updates audio/video frames (call this once every frame)
movieTexture.isActive
- the status of the video decoder (false when playback is done)movieTexture.isPlaying
- false if playback is pausedmovieTexture.currentTime
- the current time position of the video in seconds
A convenient way to load and play videos without worrying about the plugin's inner workings
newMovieRect
- returns anImageRect
preloaded with aMovieTexture
MovieRect.play
- starts/resumes video playbackMovieRect.pause
- pauses video playbackMovieRect.stop
- stops video playback and frees theMovieRect
object
MovieRect.texture
- reference to theMovieRect
'sMovieTexture
MovieRect.channel
- the channel used for audio playback (use this to set volume, etc)MovieRect.playing
- false if playback is paused
A convenient way to load and play videos in a loop without worrying about the plugin's inner workings
newMovieLoop
- returns aGroupObject
that automatically plays a video file in a loop using 2MovieRect
objectsMovieLoop.rect
- returns a handle to the currently playingMovieRect
MovieLoop.play
- starts/resumes video playbackMovieLoop.pause
- pauses video playbackMovieLoop.stop
- stops video playback and frees theMovieLoop
object as well as its associatedMovieRect
objects
MovieLoop.iteration
- the current looping iteration (equal to 1 when no looping has occurred yet)MovieLoop.playing
- false if playback is paused
- Only mono and stereo audio is supported. Videos with more than 2 audio channels might not sound as expected
- Playback speed is limited by the engine's fps. It is thus recommended to use videos with a framerate several values below your game's fps as set in
config.lua
- Depending on video resolution, memory usage could be high
- The
MovieLoop
object consumes around double the memory consumed by theMovieRect
object - The
MovieLoop
object might not work very well with really short videos (e.g: videos under 10 seconds long) - Underpowered devices might experience frame drops, audio stutters and audio/video desynchronization issues
- The plugin is susceptible to all limitations of the theoraplay library. As a result, the only valid pixel format is
TH_PF_420
. This, however, shouldn't be an issue for most use-cases - It is recommended to remove all other
enterFrame
event listeners before video playback to ensure smooth playback - It is recommended to wait around half a second after initializing any of the movie objects to allow for buffering of frames
ffmpeg -i video.mp4 -c:v libtheora -q:v 7 -c:a libvorbis -q:a 5 -pix_fmt yuv420p video.ogv
- theoraplay by @icculus
- Insipired by the theora plugin by @ggcrunchy as well as a video wrapper provided by a user of the Solar2D discord
- macOS and iOS builds by @kwiksher