Cannot go to another scene after a video is completed

Hello,

I have a main.lua, that tells my app to go to another a scene (intro.lua), which is a video playing, and after the video is completed, I want to go to a third scene which is my game menu (menu.lua).

The problem is that my Android app stops, when the video is completed. It doesnt go to the “menu” scene.

My code is as follows:

My main.lua:

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() system.setIdleTimer( false ) display.setStatusBar( display.HiddenStatusBar ) yourName="" labName="" titleName="" rememberMusic=1 rememberSound=1 remeberMusicSlider=300 remeberSoundSlider=300 sndMusic = audio.loadStream ( "Audio/ambient.mp3" ) sndClick = audio.loadStream ( "Audio/click.mp3" ) storyboard.gotoScene("intro") return scene

My video intro.lua:

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() system.setIdleTimer( false ) display.setStatusBar( display.HiddenStatusBar ) local onComplete = function() storyboard.gotoScene("menu") end media.playVideo( "videos/logo.mp4", false, onComplete ) return scene

my menu.lua is huge, I cannot post it here. But it has no problem. If I call it from my main.lua, it works great. If I call from my intro.lua (without the video) it works great.

BUT if I call it (as written in the code above) WHEN the video is completed, the app stops.

Anyone has an idea what is going on?

On Android, the video plays in another process and your app gets backgrounded.  You need to handle the suspend and resume events and process your gotoScene(“menu”) when your app resumes from the playback.

Can you give me an example? cause Im new to Corona

local function systemEvents(event)     print("systemEvent " .. event.type)     if event.type == "applicationSuspend" then         print("suspending......")     elseif event.type == "applicationResume" then         print("resuming............................. ")         -- do stuff here to resume your app.      elseif event.type == "applicationExit" then         print("exiting......")     end     return true end Runtime:addEventListener("system", systemEvents)

Keep in mind that resume will fire everytime someone resumes your app like after backgrounding it, letting the app go to sleep, etc.  You will need to probably set some kind of flag that your video is playing and if you resume and your video was playing then do your storyboard.gotoScene().

Doesn’t the Resuming event happen automatically when the video ends?

yes. 

well I used your code, and ordered it to go to scene when the app is resumed. The result is the same. It stops my app. It doesn’t resume automatically after the video ends. It just stops.

I use Nexus 7.

You are probably going to have to put some print statements in various parts of your code like your onComplete handler, in the stuff I provided and see what’s going on.

I just checked it on a Galaxy Fame and a Galaxy S3. It works perfectly on them.

It doesn’t work on my Nexus 7.

I ll try to find more tablets from friends and test it.

To be frank I wished that I was the one doing something wrong. It seems the problem is on Nexus.

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() system.setIdleTimer( false ) display.setStatusBar( display.HiddenStatusBar ) local onComplete = function() print("video ended..................") storyboard.gotoScene("menu") end media.playVideo( "videos/logo.mp4", false, onComplete ) return scene

When the video ends, it doesn’t print “video ended…”. It doesn’t even go to onComplete function. The app is terminated after the video ends.

And one more. The video doesn’t even take account the orientaion (which for me is landscape). If I turn my device while the video is playing, the video is going portrait. In short it seems it ignores any of my code. Just plays and then stops.

This is groundbreaking, it ruins my whole game design. Can a Corona Staff member test with a small video on Nexus 7 so that it confirms the problem and maybe a solution? cause I ve tried EVERYTHING.

And there’s more cross-android devices issues, like Galaxy S3 showing my input text fields cropped as described in http://forums.coronalabs.com/topic/29724-my-input-text-is-cut-off-halfway-on-some-android-devices-pls-help/page-2#entry190942.

The Optimus LG 3D on the other hand doesn’t even play the video, just some artifacts, and doesn’t EVEN open the virtual keyboard when I press my input text field!

All in all, Android seems to have poor support from corona.

local function systemEvents(event) print("systemEvent " .. event.type) if event.type == "applicationSuspend" then print("suspending......") elseif event.type == "applicationResume" then print("resuming............................. ") -- do stuff here to resume your app. elseif event.type == "applicationExit" then print("exiting......") end return true end Runtime:addEventListener("system", systemEvents)

After the “if event.type == “applicationSuspend” then”  Can I manually with code here tell that if the suspend event occurs, to resume the application?I searched and didn;t find such a method.

On Android, the video plays in another process and your app gets backgrounded.  You need to handle the suspend and resume events and process your gotoScene(“menu”) when your app resumes from the playback.

Can you give me an example? cause Im new to Corona

local function systemEvents(event)     print("systemEvent " .. event.type)     if event.type == "applicationSuspend" then         print("suspending......")     elseif event.type == "applicationResume" then         print("resuming............................. ")         -- do stuff here to resume your app.      elseif event.type == "applicationExit" then         print("exiting......")     end     return true end Runtime:addEventListener("system", systemEvents)

Keep in mind that resume will fire everytime someone resumes your app like after backgrounding it, letting the app go to sleep, etc.  You will need to probably set some kind of flag that your video is playing and if you resume and your video was playing then do your storyboard.gotoScene().

Doesn’t the Resuming event happen automatically when the video ends?

yes. 

well I used your code, and ordered it to go to scene when the app is resumed. The result is the same. It stops my app. It doesn’t resume automatically after the video ends. It just stops.

I use Nexus 7.

You are probably going to have to put some print statements in various parts of your code like your onComplete handler, in the stuff I provided and see what’s going on.

I just checked it on a Galaxy Fame and a Galaxy S3. It works perfectly on them.

It doesn’t work on my Nexus 7.

I ll try to find more tablets from friends and test it.

To be frank I wished that I was the one doing something wrong. It seems the problem is on Nexus.

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() system.setIdleTimer( false ) display.setStatusBar( display.HiddenStatusBar ) local onComplete = function() print("video ended..................") storyboard.gotoScene("menu") end media.playVideo( "videos/logo.mp4", false, onComplete ) return scene

When the video ends, it doesn’t print “video ended…”. It doesn’t even go to onComplete function. The app is terminated after the video ends.

And one more. The video doesn’t even take account the orientaion (which for me is landscape). If I turn my device while the video is playing, the video is going portrait. In short it seems it ignores any of my code. Just plays and then stops.

This is groundbreaking, it ruins my whole game design. Can a Corona Staff member test with a small video on Nexus 7 so that it confirms the problem and maybe a solution? cause I ve tried EVERYTHING.

And there’s more cross-android devices issues, like Galaxy S3 showing my input text fields cropped as described in http://forums.coronalabs.com/topic/29724-my-input-text-is-cut-off-halfway-on-some-android-devices-pls-help/page-2#entry190942.

The Optimus LG 3D on the other hand doesn’t even play the video, just some artifacts, and doesn’t EVEN open the virtual keyboard when I press my input text field!

All in all, Android seems to have poor support from corona.