Need Help With Video Extension

Peace Unto You! Okay so I’ve hit another wall in this. I’ve tried many variations of the code. I tried to have the video player be destroyed at a delay, disabled then load the main menu, now in the code I have a fail safe system that allows the main menu to load regardless of if the videoplayer is disabled or destroyed, and in the code it said both the main menu has been enabled and loaded, but the video player still appears on top of everything.

After some digging I theorized since the video player isnt native to Defold, the Z order of the video player go means nothing because my main menu z order is higher than everything else, so now I’m running into the same issue where, after the video ends the main menu doesn’t load. I put in the code to disable first then destroy, but even still since the fail safe is active the main menu isnt waiting for the video to be destroyed to appear but apparently the videoplayer will always appear on top of every collection and go.

Is there a way to prevent the videoplayer from always appear on top of everything?

Also me adding the delay didn’t fix the issue cause the main menu doesn’t show, and when I directly call for the video to be destroyed, the game just crashes. So why does the video player have this power?

Here are the errors I was getting from the debugger when I ran the game on my iPhone after the video ended

ERROR:GAMESYS: The collection /mainmenu/mainmenu.collectionc is already enabled Message ‘enable’ sent from loader:/go#loader to loader:/go#mainmenu.

ERROR:GAMESYS: Collection proxy already loaded: ‘/mainmenu/mainmenu.collectionc’ Message ‘load’ sent from loader:/go#loader to loader:/go#mainmenu.

ERROR:GAMEOBJECT: Component ‘/go#videoplayer’ could not be found when dispatching message ‘disable’ sent from mainmenu:/videoplayer#videoplayer

WARNING:GAMEOBJECT: Failed to call message response callback function, has it been deleted?

WARNING:DLIB: Failed to send announce message (-8)

RESOURCE_NOTIFY trigger for THEETHERS [2623] (45001 CPU wakes over 55.00s seconds, violating limit of 45000 CPU wakes over 300.00s seconds)

Received CPU wakes trigger:
THEETHERS[2623] () woke the CPU 45001 times over 55.95 seconds (average 804/sec), violating a CPU wakes limit of 45000 over 300 seconds.

Here’s my scripts.

Video player script:

local function log(msg)
print(msg)
end

local function video_callback(self, video, event, data)
log(string.format("VIDEO CALLBACK: video %d evt: %d ", video, event))

if event == videoplayer.VIDEO_EVENT_READY then
log("videoplayer.VIDEO_EVENT_READY")
videoplayer.start(video)
elseif event == videoplayer.VIDEO_EVENT_FINISHED then
log("videoplayer.VIDEO_EVENT_FINISHED")
msg.post(".", "video_end") -- Trigger message instead of immediate destruction
elseif event == videoplayer.VIDEO_EVENT_FAILED then
log("videoplayer.VIDEO_EVENT_FAILED")
msg.post(".", "video_end") -- Call end function on failure via message
else
log("Unexpected event")
end
end

function video_begin(self)
if videoplayer then
log("Loading video...")

local videos = {"Intro.mp4"} -- Ensure this matches your file name exactly
self.video = videoplayer.create(videos[1], {play_sound = true}, video_callback)

if not self.video then
log("Can't create another video")
msg.post(".", "video_end")
else
log("Video created successfully: " .. self.video)
end
else
log("Could not initialize fullscreen videoplayer (on this platform?)")
end
end

function video_end(self)
log("Video playback ended")

-- Try to hide the video player by sending the disable message
local success = msg.post("mainmenu:/go#videoplayer", "disable") -- Attempt to disable the video player

if success then
log("Video player disabled successfully.")
else
log("Failed to disable the video player.")
end

-- Attempt to load the main menu regardless
msg.post("loader:/go#loader", "load_menu")

-- Wait for a short delay before checking if the menu is loaded
timer.delay(2.0, false, function()
msg.post(".", "check_menu_loaded") -- Notify that we are ready to check if the menu is loaded
end)

self.video = nil
end

function check_menu_loaded(self)
-- Here you could check if the main menu is loaded
-- If it is, destroy the video
if self.is_menu_loaded then -- Assuming you set this variable when the menu is loaded
log("Main menu is loaded, destroying video.")
videoplayer.destroy(self.video) -- Destroy the video only if the menu is loaded
else
log("Main menu is not loaded yet.")
end
end

function init(self)
msg.post(".", "acquire_input_focus")
self.video = nil
self.is_menu_loaded = false -- Initialize menu loaded state
video_begin(self) -- Start the video as soon as the game initializes
end

function on_message(self, message_id, message, sender)
if message_id == hash("video_end") then
video_end(self)
elseif message_id == hash("menu_loaded") then
self.is_menu_loaded = true -- Set flag to indicate menu is loaded
log("Menu loaded confirmed.")
end
end

Loader Script:

local function load_menu(self)
msg.post("go#mainmenu", "load")
msg.post("go#mainmenu", "enable")
end

local function unload_menu(self)
msg.post("go#mainmenu", "unload")
end

local function load_main(self)
msg.post("go#main", "load")
msg.post("go#main", "enable")
end

function init(self)
msg.post(".", "acquire_input_focus")
load_menu(self) -- Load the main menu initially
end

function on_message(self, message_id, message, sender)
if message_id == hash("start_game") then
unload_menu(self)
load_main(self)
elseif message_id == hash("load_menu") then
load_menu(self) -- Make sure this loads the main menu
end
end