So if you’ve spent any time with Corona, you know it’s pretty evolved as far as what you can do and the device options you have access to. Recording audio, video and random data, playing internet video and calling native webViews.
One really powerful function is the recording of video and saving it locally on a device. Corona has a tutorial for recording video, but it doesn’t explicitly discuss saving what you’ve recorded. A Corona SDK developer Eja has posted a really useful forum thread detailing how to save a video, with Corona, using json logic. I wanted to repost it to just make sure that it exists outside of the forums and people can find it later on.
http://forums.coronalabs.com/topic/43203-solved-saving-captured-video/#entry224933
One really powerful function is the recording of video and saving it locally on a device. Corona has a tutorial for recording video, but it doesn’t explicitly discuss saving what you’ve recorded. A Corona SDK developer Eja has posted a really useful forum thread detailing how to save a video, with Corona, using json logic. I wanted to repost it to just make sure that it exists outside of the forums and people can find it later on.
http://forums.coronalabs.com/topic/43203-solved-saving-captured-video/#entry224933
And here's the code, for posterity:
local function copyVideoFile(videoPath,dstName,dstPath)
local rfilePath=videoPath
local wfilePath=system.pathForFile(dstName,dstPath)
local rfh=io.open(rfilePath,"rb")
local wfh=io.open(wfilePath,"wb")
if not(wfh) then
return false
else
local data=rfh:read("*a")
if not(data) then
return false
else
if not(wfh:write(data)) then
return false
end
end
end
rfh:close()
wfh:close()
return true
end
local function onVideoComplete(event)
if (event.completed) then
local videoFileExtension=".mov"
if (system.getInfo("platformName")=="Android") then
videoFileExtension=".mp4"
end
local videoFilePath=string.sub(event.url,8,-1)
local savedVideoFileName="video"..videoFileExtension
local savedVideoDirectory=system.TemporaryDirectory
if (copyVideoFile(videoFilePath,savedVideoFileName,savedVideoDirectory)) then
--your video is now saved under (savedVideoDirectory) directory
--and the filename of the video is (savedVideoFileName)
--do whatever you need to do :)
local function mediaPlayListener(event)
print("video ended")
end
media.playVideo(savedVideoFileName,savedVideoDirectory,true,mediaPlayListener)
end
end
end
media.captureVideo({listener=onVideoComplete,preferredQuality="high",preferredMaxDuration=20})
local function copyVideoFile(videoPath,dstName,dstPath)
local rfilePath=videoPath
local wfilePath=system.pathForFile(dstName,dstPath)
local rfh=io.open(rfilePath,"rb")
local wfh=io.open(wfilePath,"wb")
if not(wfh) then
return false
else
local data=rfh:read("*a")
if not(data) then
return false
else
if not(wfh:write(data)) then
return false
end
end
end
rfh:close()
wfh:close()
return true
end
local function onVideoComplete(event)
if (event.completed) then
local videoFileExtension=".mov"
if (system.getInfo("platformName")=="Android") then
videoFileExtension=".mp4"
end
local videoFilePath=string.sub(event.url,8,-1)
local savedVideoFileName="video"..videoFileExtension
local savedVideoDirectory=system.TemporaryDirectory
if (copyVideoFile(videoFilePath,savedVideoFileName,savedVideoDirectory)) then
--your video is now saved under (savedVideoDirectory) directory
--and the filename of the video is (savedVideoFileName)
--do whatever you need to do :)
local function mediaPlayListener(event)
print("video ended")
end
media.playVideo(savedVideoFileName,savedVideoDirectory,true,mediaPlayListener)
end
end
end
media.captureVideo({listener=onVideoComplete,preferredQuality="high",preferredMaxDuration=20})