Jump to content

Video on Register


CodX

Recommended Posts

Posted

Hello !

It's posible to place a mp4 media file onto account-system, like a trailer, to replace the image ?

If yes, can you help me to make that script ?

Posted (edited)

try using this

Wiki Code: createBrowser

Spoiler

-- This is an example off of the wiki. I know browsers are a bit complicated.
-- https://wiki.multitheftauto.com/wiki/CreateBrowser

--In order to render the browser on the full screen, we need to know the dimensions.
local sx,sy = guiGetScreenSize()

--Let's create a new browser in local mode. We will not be able to load an external URL.
local webBrowser = createBrowser(sx,sy,true,false)

--This is the function to render the browser.
function webBrowserRender()
	--Render the browser on the full size of the screen.
	dxDrawImage(0,0,sx,sy,webBrowser,0,0,0,tocolor(255,255,255,255),true)
end

	--The event onClientBrowserCreated will be triggered, after the browser has been initialized.
	--After this event has been triggered, we will be able to load our URL and start drawing.
	addEventHandler('onClientBrowserCreated',webBrowser,function()
	--After the browser has been initialized, we can load our file.
	loadBrowserURL(webBrowser,'http://mta/local/html/site.html')
	--Now we can start to render the browser.
	addEventHandler('onClientRender',root,webBrowserRender)
end)

 


My code:

Spoiler

-- Create a table of browsers
browsers = {}

-- Then create a function to create the browser
function dxDrawWebBrowser(x,y,w,h,url)
	-- creating a table for its data
	local self = {}
	self.x = x
	self.y = y
	self.w = w
	self.h = h
	self.url = url
	-- using a toggle for visibility
	self.visible = true
	-- creating the browser
	self.browser = createBrowser(self.x,self.y)

	-- creating a draw function for dx
	self.draw = function()
		dxDrawImage(self.x,self.y,self.x+self.w,self.y+self.h,self.browser,0,0,0,tocolor(255,255,255,255),true)
	end
	
	-- inserting it all to a table so we can grab data
	table.insert(browsers,self)
end

-- single global event so that we don't keep creating events
addEventHandler('onClientBrowserCreated',resourceRoot,function()
	for i,v in pairs(browsers) do
		if source == v.browser then
			-- loading its url after grabbing its data
			loadBrowserURL(source,v.url)
		end
	end
end)

-- and this is just to put it on the screen..
addEventHandler('onClientRender',resourceRoot,function()
	for i,v in pairs(browsers) do
		if v.visible == true then
			v.draw()
		end
	end
end)


-- so after all that code we can finally create a browser..
local sx,sy = guiGetScreenSize()

-- using 0.5 to take literally half the screen..
local newbrowser = dxDrawWebBrowser(sx*0.5,sy*0.5,sx*0.5,sy*0.5,'http://www.google.com/') -- there you go.
-- and to change its visibility now just simply do this
newbrowser.visible = false

-- I hope this helped you.

 

 

Edited by ShayF
  • Moderators
Posted
1 hour ago, CodX said:

Work, but video isn't rendered.

Then you post your code, as simple as that...

Posted
2 hours ago, ShayF said:

try using this

Wiki Code: createBrowser

  Hide contents


 
-- This is an example off of the wiki. I know browsers are a bit complicated.
-- https://wiki.multitheftauto.com/wiki/CreateBrowser

--In order to render the browser on the full screen, we need to know the dimensions.
local sx,sy = guiGetScreenSize()

--Let's create a new browser in local mode. We will not be able to load an external URL.
local webBrowser = createBrowser(sx,sy,true,false)

--This is the function to render the browser.
function webBrowserRender()
	--Render the browser on the full size of the screen.
	dxDrawImage(0,0,sx,sy,webBrowser,0,0,0,tocolor(255,255,255,255),true)
end

	--The event onClientBrowserCreated will be triggered, after the browser has been initialized.
	--After this event has been triggered, we will be able to load our URL and start drawing.
	addEventHandler('onClientBrowserCreated',webBrowser,function()
	--After the browser has been initialized, we can load our file.
	loadBrowserURL(webBrowser,'http://mta/local/html/site.html')
	--Now we can start to render the browser.
	addEventHandler('onClientRender',root,webBrowserRender)
end)

 


My code:

  Reveal hidden contents


 
-- Create a table of browsers
browsers = {}

-- Then create a function to create the browser
function dxDrawWebBrowser(x,y,w,h,url)
	-- creating a table for its data
	local self = {}
	self.x = x
	self.y = y
	self.w = w
	self.h = h
	self.url = url
	-- using a toggle for visibility
	self.visible = true
	-- creating the browser
	self.browser = createBrowser(self.x,self.y)

	-- creating a draw function for dx
	self.draw = function()
		dxDrawImage(self.x,self.y,self.x+self.w,self.y+self.h,self.browser,0,0,0,tocolor(255,255,255,255),true)
	end
	
	-- inserting it all to a table so we can grab data
	table.insert(browsers,self)
end

-- single global event so that we don't keep creating events
addEventHandler('onClientBrowserCreated',resourceRoot,function()
	for i,v in pairs(browsers) do
		if source == v.browser then
			-- loading its url after grabbing its data
			loadBrowserURL(source,v.url)
		end
	end
end)

-- and this is just to put it on the screen..
addEventHandler('onClientRender',resourceRoot,function()
	for i,v in pairs(browsers) do
		if v.visible == true then
			v.draw()
		end
	end
end)


-- so after all that code we can finally create a browser..
local sx,sy = guiGetScreenSize()

-- using 0.5 to take literally half the screen..
local newbrowser = dxDrawWebBrowser(sx*0.5,sy*0.5,sx*0.5,sy*0.5,'http://www.google.com/') -- there you go.
-- and to change its visibility now just simply do this
newbrowser.visible = false

-- I hope this helped you.

 

 

Don't work your code.

Give me error: ERROR: account\login-panel\client.lua:82: attempt to index local 'newbrowser' (a nil value)

 

 

 

 

 

 

 

1 hour ago, IIYAMA said:

Then you post your code, as simple as that...

This is:

		-- This is an example off of the wiki. I know browsers are a bit complicated.
		-- https://wiki.multitheftauto.com/wiki/CreateBrowser

		--In order to render the browser on the full screen, we need to know the dimensions.
		local sx,sy = guiGetScreenSize()

		--Let's create a new browser in local mode. We will not be able to load an external URL.
		local webBrowser = createBrowser(sx,sy,true,false)

		--This is the function to render the browser.
		function webBrowserRender()
			--Render the browser on the full size of the screen.
			dxDrawImage(0,0,sx,sy,webBrowser,0,0,0,tocolor(255,255,255,255),true)
		end

			--The event onClientBrowserCreated will be triggered, after the browser has been initialized.
			--After this event has been triggered, we will be able to load our URL and start drawing.
			addEventHandler('onClientBrowserCreated',webBrowser,function()
			--After the browser has been initialized, we can load our file.
			loadBrowserURL(webBrowser,'https://www.facebook.com/iulian.macovei.904/videos/1932180010376910/')
			--Now we can start to render the browser.
			addEventHandler('onClientRender',root,webBrowserRender)
		end)

 

  • Moderators
Posted (edited)

Did you check if this video is available without being logged in?

Afaik, you shouldn't be able to view Facebook video's if you aren't.

Edited by IIYAMA
Posted
8 hours ago, ShayF said:

I'll make some code and test it before posting, give me a few hours.

Ok

 

10 hours ago, IIYAMA said:

Did you check if this video is available without being logged in?

Afaik, you shouldn't be able to view Facebook video's if you aren't.

Yes, work without login.

Spoiler



 

  • Moderators
Posted

You didn't check the whitelist, pfff

 

local screenWidth, screenHeight = guiGetScreenSize()

function webBrowserRender()
	dxDrawImage(0, 0, screenWidth, screenHeight, webBrowser, 0, 0, 0, tocolor(255,255,255,255), true)
end

requestBrowserDomains({ "www.facebook.com" }, false)

local facebookWasAccepted
local webBrowser = createBrowser(screenWidth, screenHeight, false, false)

addEventHandler('onClientBrowserCreated',webBrowser, webBrowserCreated)

addEventHandler("onClientBrowserWhitelistChange", root,
function (newDomains)
	if not facebookWasAccepted then
		for i=1, #newDomains do
			if newDomains[i] == "www.facebook.com" then
				facebookWasAccepted = true
				break
			end
		end
		if facebookWasAccepted then
			loadBrowserURL(webBrowser,'https://www.facebook.com/iulian.macovei.904/videos/1932180010376910/')
		end
	end
end)


function webBrowserCreated ()
	
	addEventHandler('onClientRender',root,webBrowserRender)
	
	if not isBrowserDomainBlocked("www.facebook.com") then
		loadBrowserURL(webBrowser,'https://www.facebook.com/iulian.macovei.904/videos/1932180010376910/')
		facebookWasAccepted = true
	end
end

 

Posted
On 10/23/2017 at 19:32, IIYAMA said:

You didn't check the whitelist, pfff

 


local screenWidth, screenHeight = guiGetScreenSize()

function webBrowserRender()
	dxDrawImage(0, 0, screenWidth, screenHeight, webBrowser, 0, 0, 0, tocolor(255,255,255,255), true)
end

requestBrowserDomains({ "www.facebook.com" }, false)

local facebookWasAccepted
local webBrowser = createBrowser(screenWidth, screenHeight, false, false)

addEventHandler('onClientBrowserCreated',webBrowser, webBrowserCreated)

addEventHandler("onClientBrowserWhitelistChange", root,
function (newDomains)
	if not facebookWasAccepted then
		for i=1, #newDomains do
			if newDomains[i] == "www.facebook.com" then
				facebookWasAccepted = true
				break
			end
		end
		if facebookWasAccepted then
			loadBrowserURL(webBrowser,'https://www.facebook.com/iulian.macovei.904/videos/1932180010376910/')
		end
	end
end)


function webBrowserCreated ()
	
	addEventHandler('onClientRender',root,webBrowserRender)
	
	if not isBrowserDomainBlocked("www.facebook.com") then
		loadBrowserURL(webBrowser,'https://www.facebook.com/iulian.macovei.904/videos/1932180010376910/')
		facebookWasAccepted = true
	end
end

 

Don't work.

Just sended me a messaje to allow facebook. I allowed that site and then he don't create website.

 

Sorry for my english.

  • Moderators
Posted

Works for me on localhost.

 

This might solve your issue: (use it when the browser has been created)

focusBrowser ( webBrowser  )
focusBrowser ( nil  )

 

Posted

I don't want to focus because the player can't login.

I wan't that video to play in background, like a picture.

  • Moderators
Posted (edited)

Please read those two lines better. Because at the end it is not focused.

Edited by IIYAMA
Posted

Don't work.

local screenWidth, screenHeight = guiGetScreenSize()
function webBrowserRender()
	dxDrawImage(0, 0, screenWidth, screenHeight, webBrowser, 0, 0, 0, tocolor(255,255,255,255), true)
end

requestBrowserDomains({ "www.facebook.com" }, false)

local facebookWasAccepted
local webBrowser = createBrowser(screenWidth, screenHeight, false, false)
addEventHandler("onClientBrowserCreated", browser,
   function ()
       focusBrowser(source)
   end
)

addEventHandler('onClientBrowserCreated',webBrowser, webBrowserCreated)

addEventHandler("onClientBrowserWhitelistChange", root,
function (newDomains)
	if not facebookWasAccepted then
		for i=1, #newDomains do
			if newDomains[i] == "www.facebook.com" then
				facebookWasAccepted = true
				break
			end
		end
		if facebookWasAccepted then
			loadBrowserURL(webBrowser,'https://www.facebook.com/iulian.macovei.904/videos/1932180010376910/')
		end
	end
end)


function webBrowserCreated ()
	
	addEventHandler('onClientRender',root,webBrowserRender)
	
	if not isBrowserDomainBlocked("www.facebook.com") then
		loadBrowserURL(webBrowser,'https://www.facebook.com/iulian.macovei.904/videos/1932180010376910/')
		facebookWasAccepted = true
	end
	focusBrowser ( webBrowser  )
	focusBrowser ( nil  )
end

 

  • Moderators
Posted

If you don't debug your code manually, then you don't work either. Sounds like a great match to me.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...