Media player

Tutorial

·

intermediate

·

+10XP

·

30 mins

·

(8)

Unity Technologies

Media player

Media players are incredibly useful for mixed-reality experiences like those you might want to design for the Magic Leap 2, whether you’re displaying instructional videos or entertainment content. Plus, in mixed reality, there’s no limit to the number or the size of the screens you can add.

In this tutorial, you will learn how to add a media player to your Unity scenes, including an example of a typical use case where the user combines the media player with global dimming and voice commands.

1. Overview

Why use media players?

Media players can provide a convenient way for users to consume multimedia content within the mixed reality environment. For example, a user in a virtual museum might use a media player to watch a video about a particular exhibit.

Or if you’re designing a training application for medical technicians or factory employees, for example, step-by-step video walkthroughs could be highly beneficial.

What will you learn in this tutorial?

In this tutorial, you will learn how to add a media player to your Unity scenes.

2. Before you begin

Before you begin working through this tutorial, you should make sure your development environment is set up for Magic Leap 2 development and download the example prototype project.

Set up your development environment

If this is your first time developing in Unity for the Magic Leap 2, make sure you have your development environment configured properly using one of the following guided options:

Download and open the example prototype

This tutorial will guide you through the implementation of this feature in your own application using an example prototype. If you want to explore the code of the prototype yourself, download the accompanying prototype project and open it in Unity.

3. Basic media player setup

Export Magic Leap 2’s MediaPlayer prefab

Magic Leap 2 provides a very useful media player prefab in their example scene. You can follow the instructions in this tutorial to install and set up the SDK examples project. You can then export the MediaPlayer prefab as a UnityPackage.

Import the MediaPlayer prefab

The MediaPlayer prefab should look something like the image below when you import it into your own project. You’ll notice the prefab has all of the basic functionality you would want in a media player, including playback and volume controls.

4. Video options

Source options

With the media player in your scene, you can select how you want to embed your chosen video in your scene. The provided prefab’s Magic Leap Media Player Behavior script allows for the following Path Source Types:

  • Web: simply enter the URL for the video. This link cannot be a YouTube or Vimeo video — it has to be a link to an actual hosted file (for example, ending in .mp4).
  • Streaming Assets: you can create a folder in your project assets folder named “StreamingAssets”, then place a video inside it. Then for the Source path, enter the path relative to that folder (refer to the example image below).

Important: You must include the file extension in the path (for example, video.mp4).

Media codecs

You can find the list of supported video and audio codecs in Magic Leap’s Media Codecs documentation.

3D Stereo Mode

The Stereo Mode property allows you to play 3D video with either Side by Side 3D or Over Under 3D.

However, as is mentioned in the Media Player documentation, in order for stereo rendering to function, the shader used as the video render material must support the Video Stereo Mode property. An example of this functionality is provided in the Magic Leap/Stereo Video Render shader.

5. Media player in context

Now that you know how to set up a simple media player, let’s check out an example of how this feature can be combined with other interactive functionality.

In this example, plane detection is used to place the video, the controller bumper is used to play and pause a video, the menu button toggles Global Dimming, and the Y value on the touchpad dynamically controls the dimming value.

To learn how to implement this functionality yourself, the code is provided below. You can review all of the code for this demo in the example prototype project.

6. Next steps and additional resources

In this tutorial, you learned about the Media Player on the Magic Leap 2. You can learn more about the Media Player with the following resources:

You may also want to learn more about out the other features highlighted in the example prototype:

Otherwise, feel free to go back to the overview page, where you can explore other tutorials and resources.

Complete this tutorial