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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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

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

Try this :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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

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

I will test this out myself on a device and come up with a solution for you :)

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.

@lbolduc

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

Thanks

Zip is on its way. Thanks so much for your help!

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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

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?

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 :)

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.

The code successfully worked for me on a iPhone 3gs. Maybe the issue lays elsewhere perhaps

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 :)

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

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 :P

I will forward this on to the other team members who can test it on a iPad for you :)

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 :)

Thanks, again, for your time. I appreciate it.

Problem solved!

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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

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.

views:1911 update:2011/10/11 15:24:38
corona forums © 2003-2011