This is a relatively straightforward task.
Perhaps the simplest way of accomplishing this is to check if a specific file exists when the app starts. If it doesn’t, create it. If it does, then load its contents. The contents can be as simple as a “1” and “0” or “true” and “false”.
Then, you use this information in your game file to check if the video has been watched and update the file once the video has been watched to prevent unwanted future showings of the video.
Here’s the sample code:
-- main.lua: ------------ local path = system.pathForFile( "videoShown.txt", system.DocumentsDirectory ) local file = io.open( path, "r" ) if not file then videoShown = false -- create a simple global variable for ease & simplicity local path = system.pathForFile( "videoShown.txt", system.DocumentsDirectory ) local file = io.open( path, "w" ) file:write( "false" ) io.close( file ) else local contents = file:read( "\*a" ) if contents == "false" then videoShown = false else videoShown = true end io.close( file ) end file = nil -- game.lua (i.e. where the levels are played) ------------ local videoShown = videoShown or false -- get the global variable's values or default to false if not videoShown then local onComplete = function( event ) local path = system.pathForFile( "videoShown.txt", system.DocumentsDirectory ) local file = io.open( path, "w" ) if file then file:write( "true" ) io.close( file ) end -- video has been shown and videoShown.txt saved as true, so start the level end media.playVideo( "video/yourVideo.mp4", false, onComplete ) else -- video already shown, so start the level end
If you need help getting the code to your app or with something else, feel free to send me a private message or contact me at eetu@erantanen.com.