CEF Tutorial

From Multi Theft Auto: Wiki
Revision as of 20:43, 22 February 2015 by Jusonex (talk | contribs) (Jusonex moved page CEF resource management to CEF Tutorial)
Jump to navigation Jump to search

This page explains how you can access local or remote resources on the one hand and the related restrictions on the other hand.

How to load local HTML files

Loading local HTML files works similar to loading images.

Add your HTML files to your meta.xml through the file tag:

<file src="html/myAwesomeUI.html"/>

How to load local resources in local HTML files

Imagine you want to load an image or play a video from your MTA resource. This is possible via a custom URI scheme named mtalocal://

Example

This examples shows how to play a video. Note that you have to enable OOP.

Lua

-- Create a browser (local mode is also required to access local data)
local webView = Browser.create(640, 480, true, true)

addEventHandler("onClientBrowserCreated", webView,
     function()
    
          -- Load HTML UI
          webView:loadURL("html/myVideo.html")

     end
)

meta.xml

<file src="html/myVideo.html"/>
<file src="media/myVideo.webm"/>

HTML

This is the most interesting part:

[html]
<!DOCTYPE HTML>
<html>
<head></head>
<body>
    <video width="640" height="480" controls>
         <source src="mtalocal://media/myVideo.webm" type="video/webm"/>
    </video>
</body>
</html>