Need Help With Video Extension

Peace Unto You! May someone please assist me with a step by step guide on how to use this video player extension to play my video as my intro cutscene before my main menu shows?

I have NO IDEA how to use extensions so please be thorough with your explanation as I don’t have knowledge on how to use video extensions

Here’s the git hub link leading to the video extension I need

And it’s also confusing that I’m hearing information saying that you need a lua to player the video but the lua doesn’t come with the extension. All of it is confusing. It’s pretty frustrating cause there’s no clear information on it everyone just talks as if they know the basics. The manual doesn’t even make sense. It isn’t new user friendly at all

1 Like

If you download the whole release on GitHub, you can open the game.project with Defold. There is an example implementation of the extension in the folder main, you can see in the script file how it is used in the example.

Also, Lua is the scripting language that Defold uses. You don’t need to add Lua yourself, all Defold projects already support Lua.

By the way, do you only target Android and iOS, or do you want it to run on Windows as well? The video extension you linked is only for the native players on Android and iOS. For a player that works on Windows as well, try this extension: https://github.com/defold/extension-videoplayer-mpeg

1 Like

Peace Unto You! Thank you for your reply. Forgive me, I’m having trouble following with what you’re saying. I already have my own game, so downloading another persons release won’t help me. I need to make the videoplayer extension work for my game. I downloaded the zip link provided in the website I gave you, I hit fetch libraries, I see the videoplayer extension, but there isn’t ANY info out there detailing the step by step after.

They just tell you download the extension and expect you to know what to do after. I need a clear step by step guide. I know of the example you speak of in the link but what people don’t innerstand is those who are new to coding don’t know what that is or where to put it.

Like may you please tell me what do I do step by step after I put the link in my directory and download the extension?

Thank you

It will if you want to understand how to use the videoplayer extension.

The example project that is included with the extension contains a script file which will load and play a video file:

The gist of it is:

local videofile = "big_buck_bunny_720p_1mb.mp4"
local options =  { play_sound = true }
-- create a video player
-- start the video playback as soon as the video is ready
videoplayer.create(videofile, options, function(self, video, event, data)
	if event == videoplayer.VIDEO_EVENT_READY then
		videoplayer.start(video)
	end
end)

Peace Unto You! Thank you for your response. So after I download the video player extension. I have to make a new script and copy this video player code in a said script and it will play my video?

And do I leave my video.mp4 in the assets folder?

That, or put the code in an existing script if that makes more sense

Look at what the example project is doing. If you examine the project you see that the video is included as a bundle resource, ie as a video file inside the apk / IPA but not inside the binary game archive.

1 Like

okay thank you! It’s starting to make sense a little more but now there’s a MAJOR error which is, the code from the test project has build errors so even their example isn’t reliable. So are you able to provide an errorless code to play a video one time when game runs?

And even though you said I don’t need a lua file, why do I keep getting this error?

I see two errors:

First one is that you must call functions such as videoplayer.create() from within a lifecycle function (for instance from init)

function init(self)
    videoplayer.create(...)

Second, why are you calling require("videoplayer")? It is not done like that in the example project.

The videoplayer extension is a native extension which automatically exposes a videoplayer “instance” that is globally available.

BUT with that said please also note this:

If you intend to play video on other platforms than Android and iOS please use the extension which Halfstar shared.

Peace Unto You! Thank you, even with the adjustments, and with me making a build of the game and trying to run it on my it doesn’t work. Even with the code updates when I run my game on my iOS it’s just a black screen

Also there’s no zip link that’s apparent like in the other link so how am I supposed to use the website version?

Edit:. Okay I fixed my game to match how the example version is. I have the bundle resources right and everything. Now I’m just working on the code to make sure the code works. Still having issues with it. I see now to make this work I have to mimic the example code, and when I did my ipa file size went from 56mb to 200mb so that lets me know the video is now in the game, but now I’m having issues with playing the video. Since I have a mainmenu collection and a main collection, I need help getting the right code. Ima run some tests, but what is the right approach?

NEW EDIT: YAAAAAAY I FIXED IT!!! So one of the reasons it wasn’t showing was my video file was named “INTRO”, but my script said it was called “intro”. Here’s the script that plays the video in the beginning of the game like an intro cutscene. Simply change the id to whatever your video is.

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")
video_end(self, video)
elseif event == videoplayer.VIDEO_EVENT_FAILED then
log("videoplayer.VIDEO_EVENT_FAILED")
else
log("Unexpected event")
end
end

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

local videos = {"intro.mp4"} -- Ensure this matches your file name exactly

self.video = videoplayer.create(videos[1], {play_sound = true}, video_callback)
log(self.video)
else
log("Could not initialize fullscreen videoplayer (on this platform?)")
end

if self.video == nil then
log("Can't create another video")
video_end(self, self.video)
end
end

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

if video ~= nil then
log("Calling videoplayer.destroy", video)
videoplayer.destroy(video)
end

self.video = nil
end

function init(self)
[msg.post](http://msg.post/)(".", "acquire_input_focus")
self.video = nil
self.tick = 1

video_begin(self) -- Start the video as soon as the game initializes
end

Good job!

Peace Unto You! Thank you! but I’m having another issue! After my video ends the whole game crashes. The main menu doesn’t load after. It’s like destroy video closes the ipa.

How would I fix this? I’ve tried to use the loader but it’s not working, what would be your approach?

I would look at the device log. Connect your phone and have a look at the log and see if there’s information about the crash.

Peace Unto You! Thank you! How would I install it. I’ve seen some tutorials but when I type anything in my command line nothing installs.

Thank you for all your help!

How would you install what? The Console app is always included on macOS.

Peace Unto You! Im speaking of the iOS deploy you recommended. Just plugging the phone in and running the game doesn’t affect the debugger. How do I install what will allow me to see the debugger open when I run the game on my phone? Also note that I side load my game to my iPhone using Altstore

In the manual I linked there were two options:

  1. You can use the Console tool to read game and system log
  2. You can use the LLDB debugger to attach to a game running on device.

With the first option you just need to open the Console tool and connect your device using a cable. The device will show up and you will be able to see all activity on the device, including logs from the game and any crash information.

With the second option you need to run the game in such a way that you can attach the LLDB debugger. You can use ios-deploy (linked on the page).

I recommend that you use Option 1. The Console tool.

1 Like

Peace Unto You! OMG THANK YOU! I can finally see the debugger yaaaay. Okay so when the game crashes I get this.

So I’m finally seeing that the game is crashing. Maybe I’m not loading my main menu right or something?

What would be the best course of action? So in my videoplayer script in the video end function I figure I put some code that communicates to the loader to load menu.

How would I do this properly?


It’s kinda hard to figure out why it crashes and doesn’t load main menu

Please share that crash dump file which you can see mentioned in the console output.

Peace Unto You! Ive been doing so much research and I can’t find where the crash dup file is even at. How do I get it? Some people said it’s on the phone others say you gotta jailbreak the phone. Idk how to find it

edit: I think I found it using Xcode

Ok, so it seems an issue with calling videoplayer.destroy(). I would try to delay the call to videoplayer.destroy() and not call it from within the callback. Send a message to your script and destroy the video when the message is received.

1 Like