Reader small image

You're reading from  Build Your Own Metaverse with Unity

Product typeBook
Published inSep 2023
PublisherPackt
ISBN-139781837631735
Edition1st Edition
Tools
Concepts
Right arrow
Author (1)
David Cantón Nadales
David Cantón Nadales
author image
David Cantón Nadales

David Cantón Nadales, software engineer from Seville, Spain, with more than 15 years of experience. He is currently a Technical Leader at Grupo Viajes El Corte Inglés, a leading travel company in Europe. He has done a multitude of projects and video games with Unity, VR/AR with Oculus, Hololens, HTC Vive, DayDream and LeapMotion. He was ambassador of the Samsung community "Samsung Dev Spain", and organizer of "Google Developers Group Sevilla". He led more than 100 projects throughout his career. As a social entrepreneur stands out Grita, a social network that emerged during the confinement of COVID-19 that allowed to talk to other people and help each other psychologically. In 2022 he won the Top Developers Awards organized by Samsung.
Read more about David Cantón Nadales

Right arrow

Streaming Video Like a Cinema

We have reached the final stretch of the book and the construction of our metaverse. It is time to fill our virtual world with fun functionalities to leave a mark on our future users. In the metaverse, you can do an infinite number of activities with your friends, such as watching a video or a film. In this chapter, we are going to discover a new Unity class, called VideoPlayer.

With VideoPlayer, we can play local videos or videos from an internet address as if they were textures, on any 3D object – fun, right? Put simply, we integrate this feature, which gives us endless new ideas. For example, you could program a cinema in which to play movies or commercials anywhere in your world. Right now, your mind probably cannot stop generating new ideas.

In this chapter, I will give you the keys to set up any future video playback system on 3D objects.

In the following screenshot, you can see the final result of the magnificent cinema screen, streaming...

Technical requirements

This chapter does not have any special technical requirements, but we will start programming scripts in C#. It would be advisable to have basic knowledge of this programming language. You’ll need an internet connection to browse and download an asset from the Unity Asset Store.

We will continue with the project we created in Chapter 1. Remember that we have the GitHub repository, https://github.com/PacktPublishing/Build-Your-Own-Metaverse-with-Unity/tree/main/UnityProject, which contains the complete project that we will work on here.

Introducing the VideoPlayer class

Unity 3D’s VideoPlayer class is a useful tool to play and control videos in real time within a game or application. This class allows you to load and play videos in different format, and offers several configuration options, such as audio track selection and image quality settings.

The VideoPlayer class can be used in a wide variety of projects, from games to educational applications, to multimedia presentations. Here are some ways in which the VideoPlayer class could help your project:

  • Integrate videos into your game: If your game needs to include videos, either to introduce the plot or to show cinematic sequences, the VideoPlayer class will allow you to play videos within the game and control their playback.
  • Multimedia presentations: If you are creating an application that includes multimedia presentations or video tutorials, the VideoPlayer class can be a useful tool to play and control the videos.
  • Educational applications...

Designing our screen

In our practical example, we will create a screen similar in shape and proportion to a cinema screen or a billboard – elongated, in full HD style. The screen that we will use to play videos is nothing more than a plane. Follow these steps:

  1. Go to our main scene, MainScene.
  2. Select the GameObject | 3D Object | Plane option from the main menu bar and rename it Screen.
  3. Use the Move, Rotate, and Scale tools to shape the plane until it looks like this:
Figure 12.2 – Adding a plane to the scene

Figure 12.2 – Adding a plane to the scene

Perfect – easy, isn’t it? You have created the sketch of the video screen. Don’t worry if, later on, when you play videos it looks distorted. We will be able to modify the proportion of the screen later on.

Now that we have the GameObject that physically represents our screen, we need to add the VideoPlayer component to give it the functionality we are looking for. To do this, simply select the...

Playing videos

Earlier, in the introduction of this chapter, we saw a spoiler of what we are going to cover in this section. We will cover both local and online video playback. For this, we will need a valid URL and a valid file, which we will look at shortly.

If you’re wondering about the video formats supported by this component, here’s a look at some of the wide variety of video formats supported:

  • MP4: This is one of the most common video formats and is widely compatible with most devices
  • WEBM: This video format is especially useful for online video streaming and is often used in web applications
  • OGV: This is an open source video format that is often used in video editing software and web browsers
  • MOV: This is a video format developed by Apple and is widely supported by Apple devices
  • AVI: This is one of the oldest video formats and is compatible with most media players
  • FLV: This is a popular video format for online video streaming and...

Summary

In this chapter, we have discovered a new Unity3D class, the VideoPlayer class, which allows us to easily play videos both online via URLs and locally via video files. We have reviewed which formats this class accepts and analyzed in detail the properties of the class.

In the next chapter, we will learn how to integrate the Oculus Quest 2 with its respective SDK into our project.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Build Your Own Metaverse with Unity
Published in: Sep 2023Publisher: PacktISBN-13: 9781837631735
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime

Author (1)

author image
David Cantón Nadales

David Cantón Nadales, software engineer from Seville, Spain, with more than 15 years of experience. He is currently a Technical Leader at Grupo Viajes El Corte Inglés, a leading travel company in Europe. He has done a multitude of projects and video games with Unity, VR/AR with Oculus, Hololens, HTC Vive, DayDream and LeapMotion. He was ambassador of the Samsung community "Samsung Dev Spain", and organizer of "Google Developers Group Sevilla". He led more than 100 projects throughout his career. As a social entrepreneur stands out Grita, a social network that emerged during the confinement of COVID-19 that allowed to talk to other people and help each other psychologically. In 2022 he won the Top Developers Awards organized by Samsung.
Read more about David Cantón Nadales