<video> file in GUI

Are there security measures in place that FiveM incorporates with it’s GUI (I know it’s HTML based) to prevent certain tags from being used?

Our server is ending a season, and getting ready to launch a large update and as part of the farewell, I recorded a cool outro video, that I am trying to get to play on every client screen who participates in the end-game. (Sort of like an end-game cutscene). I have the resource that loads the script and the video, but when the resource is actually triggered (via a command), the video doesn’t play or show up on the screen.

  <video  id="myVideo">
    <source src="rain.mp4" type="video/mp4">
  </video>

Is what my video tag looks like. I use a SendNUImessage to play the video (using video.play()).

Does anybody know if there are securities in place to prevent this from happening?

Trying to load a video even with sound, the sound doesn’t play either, so I am not sure exactly what the problem is. If I run the .html file outside of FiveM, it works as it should.

No, you can use the video tag. The event might just don’t get triggered, or the video source hasn’t been found.

Please try that again and look into your players console, there should be an html error printed, if something’s wrong. If not, then you’re probably doing something wrong with sending the NUI message.

I hope I could help,
Have a nice day! :hamburger: :mascot:

1 Like

I setup some debug prints. One of them is when the event is triggered (via the command), That one prints.

The other is when the client receives the trigger event. That one prints.

All of the prints are triggering, and the setTimeout works and brings me back into the game, but the video itself does not play.

In the client console, I see no javascript errors, and I also see none in the console when accessing: http://localhost:13172/

RegisterNetEvent('the_event:showdown')
AddEventHandler('the_event:showdown', function()
  print("Triggering client event")
  TheShowdown()
end)

RegisterNUICallback('end_event',function(data, cb)
  print("stopping event")
  SetNuiFocus(false)
  SendNUIMessage({openVideo = false})
  --DoScreenFadeOut(5000)
  cb('ok')
end)

function TheShowdown()
  print("Triggering function")
  SetNuiFocus(true, false)
  SendNUIMessage({openVideo = true})
end

Then in the javascript file;


$(document).ready(function(){

	var video = document.getElementById("myVideo");

	function closeMain() {
		$("body").css("background","transparent");
		$("#myVideo").css("display","none");
		video.pause();

	}
	function openMain() {
		$("body").css("background-color","black");
		$("#myVideo").css("display","block !important");
		video.play();
	  	setTimeout(function(){
		    $.post('http://the_event/end_event', JSON.stringify({}));
	    }, 20000);
	}

	// If 'Esc' is pressed, close all the menus
	document.onkeyup == function (data) {
		if (data.which == 27) {
			$.post('http://the_event/end_event',JSON.stringify({}));
		}
	};
	
	window.addEventListener('message', function(event) {
		var item = event.data;

	    if (item.openVideo == true) {
  		  	openMain();
    	}
		if (item.openVideo == false) {
	    	closeMain();
		}
	});
})

and finally, the index.html


<html>
  <head>
    <script src="nui://game/ui/jquery.js" type="text/javascript"></script>
    <script src="script.js"></script>
    <style>
    /* Style the video: 100% width and height to cover the entire window */
    #myVideo {
      position: fixed;
      right: 0;
      bottom: 0;
      min-width: 100%;
      min-height: 100%;
      opacity: 1;
    }
    </style>
  </head>

  <!-- The video -->
  <video id="myVideo">
    <source src="rain.mp4" type="video/mp4">
  </video>
</html>

__resource.lua

description "The Event"

ui_page "html/index.html"

client_script "client.lua"

server_script "server.lua"

files {
	"html/index.html",
	"html/script.js",
	"html/rain.mp4",
}

I am not a hundred percent sure about this, but I guess that this function get’s triggered before the wait, you should try once without this function.

I have completely removed that to see if it was causing an issue, and it still does not play the video.

Hmm, maybe this site helps you: w3schools.com
It has Tutorials l for html, css and js, so it really can get helpfully, otherwise I don’t really know a solution and can’t look for one since I am on mobile currently.

Anyways, I hope the site can assist you,
then have a nice day and much luck to solve it. :hamburger: :mascot:

No worries, I hope I can find a solution. I only have a couple of days to get this situated.

I am a web developer by profession, so I have the know-how to get it working from straight HTML, which it does. The problem is the video not loading up in fivem.

At this point, I’m confident it’s either something with FiveM rejecting the tag, or not loading the video correctly. The markup works when viewing it in a normal chrome browser. At minimum, if the video was being found it should be displaying the video full screen, as a thumbnail on the screen, but it’s not even doing that.

There’s your issue.

https://www.chromium.org/audio-video

H.264: Google Chrome only

1 Like

Isn’t the browser provided with FiveM google chrome? The inspector and tools you use to inspect the HTML certainly is.

There’s a difference between open-source Chromium and closed-source Chrome, mainly involving commercial crap which includes H.264 decoding thanks to the idiots at MPEG LA.

(a H.264 decoding license costs $0.15 per ‘product’ which includes any free download. Since FiveM has been downloaded over 3 million times, that’d have cost us $450k, which we do not have, nor ever had, and if we did we’d spend it on something better than a video decoding license)

Also, it’s not implied that just because it’s mp4 its h.264. It usually is, but isn’t implied. mp4 is just the container format while h.264 is the codec used to compress it.

So any video files used in FiveM need to be vp8 or vp9 (and potentially AV1) ?

Nobody typically puts VP8/VP9 in an MP4 container, so the guess quite certainly wasn’t wrong especially seeing that your video didn’t play at all.

I’m not sure if AV1 is supported in M73 yet, and an upgrade is a bit further out due to some rewritten subsystems that we patch. VP8/VP9 ought to work.

I’ll give it a try in the morning. Hopefully it’s ready to go. Thank you for your help!

Couldn’t resist, checked tonight. It works. It’s a bit out of sync with the audio and video, but it’s probably the poor converter I used. Now that I know it works i can export is as vp9 to begin with.

Thanks again for the help!

If you want some implementation that will play mp4 then you should look at the source code for:

I have confirmed that it does work with any direct link mp4. (That I tested at least, which I know 2 of them were h.264, and audio worked properly as well)

Does it allow full screen? The way I’m doing it now, it displays over the entire screen as if it were a cutscene.

1 Like

Yes it works wonderfully.

You can maybe share your code to me? Want to use it like a cutscene aswell. Greetings :v: