onComplete ignored - movie ends. app quits.

Hi,

A new user, I’ve read movie doc, reviewed samples, scoured the forum, and tried every iteration that i can think of to solve this problem, but can’t. Scenario for iPad:

Open intro.lua. Play movie. All goes swimmingly. Movie ends. Ignores ‘onComplete’ function. App quits.

Goal: movie ends, onComplete changeScene(“menu”), open main menu. (Alternate: movie ends, reveals intro.lua bg graphics and buttons)

Here’s the current intro.lua code:

module(..., package.seeall);  
  
function new()  
  
 local localGroup = display.newGroup();  
  
 local isSimulator = "simulator" == system.getInfo("environment")  
  
 local movie = media.playVideo("media/intro.mov", true, onComplete)  
  
 local bgfull = display.newImageRect("images/bgo.png", \_W, \_H-4);  
 bgfull:setReferencePoint(display.CenterReferencePoint);  
 bgfull.x = \_W/2; bgfull.y = \_H/2;  
  
 local onComplete = function(event)  
 localGroup:remove(movie)  
 --movie:removeSelf(); --doesn't work  
 --director:changeScene("menu"); --doesn't work  
 --localGroup:insert(bgfull); --tried re-inserting before and after remove  
 end  
  
 if isSimulator then  
 msg = display.newText( "No Video on Simulator!", 0, 60, "Verdana-Bold", 22 )  
 else  
 media.playVideo(movie)  
 end  
  
 --movie:addEventListener("remove",onComplete) --proposed in forum, didn't work  
  
 localGroup:insert(bgfull);  
 localGroup:insert(movie);  
  
 return localGroup;  
  
end  

I don’t understand why changeScene doesn’t work within onComplete function. Does it need a local changeScene function like Rafael Hernandez uses in his Screen Transitions tutorial? Not sure how to convert that touch-phase-based example for passive video-complelte usage.

Current code is influenced by the forum discussion

Mobile Application Development | Working With Movie Clips @ansca #CoronaSDK

which suggests it’s possible to create a local ‘movie’ variable, insert movie into localGroup, then use onComplete to remove the movie (leaving bg images and button visible/active); but, movie still plays, ends, app quits. Seems logical; doesn’t work.

I’ve been at this for quite a while, probably missing something obvious. Does anyone see what’s missing? What I’m doing wrong? Any help you can give is greatly appreciated.

Thanks very much,

LB [import]uid: 11631 topic_id: 13789 reply_id: 313789[/import]

Hi. It doesn’t work because your code is structured wrong.

Try this :

module(..., package.seeall);  
  
function new()  
  
local localGroup = display.newGroup();  
  
local isSimulator = "simulator" == system.getInfo("environment")  
  
local movieEnded --Predeclare movieEnded function (so media.playVideo knows about it)  
  
local movie  
local movieFile = "media/intro.mov"  
  
local bgfull = display.newImageRect("images/bgo.png", \_W, \_H-4);  
bgfull:setReferencePoint(display.CenterReferencePoint);  
bgfull.x = \_W/2; bgfull.y = \_H/2;  
  
movieEnded = function(event)  
localGroup:remove(movie)  
--movie:removeSelf(); --doesn't work  
--director:changeScene("menu"); --doesn't work  
--localGroup:insert(bgfull); --tried re-inserting before and after remove  
end  
  
if isSimulator then  
msg = display.newText( "No Video on Simulator!", 0, 60, "Verdana-Bold", 22 )  
else  
movie = media.playVideo(movieFile, true, movieEnded)  
end  
  
localGroup:insert(bgfull);  
localGroup:insert(movie);  
  
return localGroup;  
  
end  

In short you can’t call a function that your code doesn’t know about yet. By pre-declaring the oncomplete (renamed to movieEnded) function, the movie playback function can actually see the function your trying to call and thus the code will actually execute. :slight_smile: [import]uid: 6981 topic_id: 13789 reply_id: 50642[/import]

Hi,

Thank you. I defined the function before calling it, but I didn’t realize that you have to declare the name of the function before defining the function itself. Thanks very much.

I tried the revised code. For some reason, it still quits immediately after the movie ends.

If you see anything else that I have done wrong, please let me know, if you have a chance.

Thanks again,

LB [import]uid: 11631 topic_id: 13789 reply_id: 50682[/import]

I will test this out myself on a device and come up with a solution for you :slight_smile: [import]uid: 6981 topic_id: 13789 reply_id: 51009[/import]

Thank you _so_ much.

Revisited Rafael Hernandez’ screen-transition tutorial re: end event > changeScene to another lua. Asked his advice. He suggested a timer to give the app more time to end the movie and switch files.

Even at 3 seconds, the video continues to play perfectly, end, quit.

Ansca’s streaming video sample (converted to local video) works as an isolated video example. Converting from tap-event-based sample to passive changeScene using built-in completion listener or completion instruction just above the playVideo declaration, just plays and quits … even w/timer.

Thanks for any help you can give.
[import]uid: 11631 topic_id: 13789 reply_id: 51121[/import]

@lbolduc

Could you please send a zip file of the problematic code & any the movie file you are using to test (if its small! :stuck_out_tongue: ) to : danny@anscamobile.com and I will look into it for you.

Thanks [import]uid: 84637 topic_id: 13789 reply_id: 51432[/import]

Zip is on its way. Thanks so much for your help! [import]uid: 11631 topic_id: 13789 reply_id: 51598[/import]

Sorry for the delay!

The below code works successfully for me. It plays the movie then returns to the menu on completion.

This is the entire intro.lua i modified.

  
module(..., package.seeall);  
  
function new()  
  
 local localGroup = display.newGroup();  
  
 local movie = "media/intro.mov";  
  
 local function goToMenu(event)  
 director:changeScene("menu", "fade");  
 return true  
 end  
  
 -- Determine if running on Corona Simulator  
 local isSimulator = "simulator" == system.getInfo("environment")  
  
 -- Video is not supported on Simulator  
 if isSimulator then  
 display.newText( "No Video on Simulator!", 0, 60, "Verdana-Bold", 22 )  
 else  
 media.playVideo( movie, true, goToMenu );   
 end  
  
 return localGroup;  
  
end  

I believe the timer.performWithDelay() you had on line 13 was causing the issue. Also probably best not to use the variable name onComplete as a function name as it can be taken for something else, since it’s a reserved keyword.

Hope that helps ! [import]uid: 84637 topic_id: 13789 reply_id: 51798[/import]

Hi Danny,

Thank you so much for the work you put into this. There’s a problem on my end.

It works better, in that the app doesn’t crash; but, after the movie plays, the screen goes black. I assume the movie ended and app stays in intro.lua which is black because there is no background graphic or there is an empty movie window?

I tried building as iPad and Universal to see if it made a difference on the device. It didn’t.

I tried placing movie.removeSelf() before/after changeScene and after return true. Still goes black.

Why would this work for you and not for me? Could it be different iPads? I have a first generation.

What the what? [import]uid: 11631 topic_id: 13789 reply_id: 51816[/import]

No probs. Did you try using only the code i posted in intro.lua and nothing else?

If not try it exactly as is and report back :slight_smile: [import]uid: 84637 topic_id: 13789 reply_id: 51817[/import]

Hi,

First, I deleted the content of the intro.lua that I sent to you and replaced it with the code you posted, exactly that and nothing else. When that didn’t work, I tried the remove code. [import]uid: 11631 topic_id: 13789 reply_id: 51819[/import]

The code successfully worked for me on a iPhone 3gs. Maybe the issue lays elsewhere perhaps [import]uid: 84637 topic_id: 13789 reply_id: 51967[/import]

Hi,

Maybe it’s a playVideo bug on the iPad?

Ironic, build and config specs are for the iPad as is the 640x480 video; it runs seamlessly on the 3g phone and not the iPad. Gotta love it :slight_smile:

If you have any epiphanies, please send them along. I posted this on the Director class forum too. Is there another ‘best’ post location? Or someone at Ansca who specializes in video code?

Thanks very much for your time.

Best,

LB [import]uid: 11631 topic_id: 13789 reply_id: 52021[/import]

I personally don’t currently have an iPad to test on which is a bit of a pain, will be getting one next month but that doesn’t help you much :stuck_out_tongue:

I will forward this on to the other team members who can test it on a iPad for you :slight_smile: [import]uid: 84637 topic_id: 13789 reply_id: 52037[/import]

That would be great. Thanks very much for your help.

Just got an iPhone 4. Tried testing on that; it can’t find a valid signing identity. All other test devices can find it. Just not the iPh4. Always an adventure :slight_smile:

Thanks, again, for your time. I appreciate it. [import]uid: 11631 topic_id: 13789 reply_id: 52114[/import]

Problem solved!

With special thanks to Ricardo Rauber, Rafael Hernandez, and Danny@ansca, this code now works on iPad 1:

[code]

module(…, package.seeall);

function new()

local localGroup = display.newGroup();

local bg = display.newImage( “Default.png” )


– CHANGE SCENE

local changeScene = function ( e )
director:changeScene( “menu” , “fade” )
end

tmr = timer.performWithDelay(50, changeScene , 1)


– PLAY VIDEO

– Determine if running on Corona Simulator
local isSimulator = “simulator” == system.getInfo(“environment”)

– Video is not supported on Simulator
if isSimulator then

display.newText( “No Video on Simulator!”, 0, 60, “Verdana-Bold”, 22 )

else

media.playVideo( “media/intro.mov”, true, changeScene );

end

localGroup:insert(bg);

return localGroup;

end
[/code] [import]uid: 11631 topic_id: 13789 reply_id: 52208[/import]

Interesting, glad to hear it works for you now!

Also thanks for posting up the fixed code, it will be helpful for anyone else who may encounter this issue. [import]uid: 84637 topic_id: 13789 reply_id: 52209[/import]