Media.captureVideo behaving differently than documentation

Currently media.captureVideo seems to not follow its documentation.
Particularly the case of a cancelled video.
A case for this would be an Android user hitting the device back button after media.captureVideo has been called.

Documentation on https://docs.coronalabs.com/api/library/media/captureVideo.html says the following.

  • event.url is a String which is the URL of the video. If the operation was cancelled, this value will be nil.
  • event.completed will be true if the user captured a video; false if the user cancelled the video capture.
  • event.duration will be the number of seconds of the video if the user captured a video; nil if the user cancelled the video capture or the value could not be obtained.
  • event.fileSize will be the number of bytes of the user captured a video; nil if the user cancelled the video capture or the value could not be obtained.

However, after running through this several times, I have found the following.

  • event.url is “” on video being cancelled
  • event.completed is ALWAYS true when the listener gets called

Duration and fileSize behave as the documentation says. 

For example, here is a table I was getting back from a failed video.

table: 0x650ce458 {

    I/Corona  (16204):   [completed] => true

    I/Corona  (16204):   [url] => “”

    I/Corona  (16204):   [name] => “completion”

    I/Corona  (16204):

}

This bug was causing me a lot of problems, since all my ways to check for the video existing were failing. 
Please update the documentation to reflect how these functions actually work.

For reference, I am using Version 2015.2634 (2015.5.13) on a Samsung Galaxy S3 running Android V 4.4.2

Hi @connor6,

Can you please post the code you’re using to capture the video, including the listener function? Also, are you sure the “event.url” is returning an empty string ("") and not nil?

Best regards,

Brent

local function callQueueSave(event) if event.url == nil or event.completed == false then -- show an error message saying video can't be found return nil elseif event.fileSize \> 10 \* (1024 \* 1024) then -- 10 \* (1MB) -- Display a message for the video being too large return nil end -- Work to actually handle the acceptable video end end if media.hasSource( media.Camera ) then media.captureVideo( { listener = callQueueSave, preferredQuality = "low", preferredMaxDuration = 15, } ) end

What happened was that the first call to “if event.url == nil or event.completed == false then” never happened, so I would get a runtime error when it later tried to compare event.fileSize (which was nil). This is what made me check, and both url and completed are different than listed. I was able to fix this issue by changing to use:

if event.url == nil or event.url == “” then

 
Checking for event.completed is even easier, since any call to check for it will ALWAYS run. 

I hope this was clear.

Hi @connor6,

Thanks for the update. Just to confirm, this implementation now works fine for you on Android in the usage case when you “cancel” with the back button? By chance did you also test this on iOS?

Thanks,

Brent

Hi @connor6,

Can you please post the code you’re using to capture the video, including the listener function? Also, are you sure the “event.url” is returning an empty string ("") and not nil?

Best regards,

Brent

local function callQueueSave(event) if event.url == nil or event.completed == false then -- show an error message saying video can't be found return nil elseif event.fileSize \> 10 \* (1024 \* 1024) then -- 10 \* (1MB) -- Display a message for the video being too large return nil end -- Work to actually handle the acceptable video end end if media.hasSource( media.Camera ) then media.captureVideo( { listener = callQueueSave, preferredQuality = "low", preferredMaxDuration = 15, } ) end

What happened was that the first call to “if event.url == nil or event.completed == false then” never happened, so I would get a runtime error when it later tried to compare event.fileSize (which was nil). This is what made me check, and both url and completed are different than listed. I was able to fix this issue by changing to use:

if event.url == nil or event.url == “” then

 
Checking for event.completed is even easier, since any call to check for it will ALWAYS run. 

I hope this was clear.

Hi @connor6,

Thanks for the update. Just to confirm, this implementation now works fine for you on Android in the usage case when you “cancel” with the back button? By chance did you also test this on iOS?

Thanks,

Brent