Play a Video Stream

Choose your OS:

A Stream Media Source is an asset that enables you to stream a video in the supported URL format inside Unreal Engine 4 (UE4). With the stream defined, you can load it up and play it inside UE4 with a Media Player asset and (with an associated Media Texture) can assign it to various aspects of your level. The stream can be loaded and played as part of a UI element, played fullscreen or even applied to a Static Mesh (such as a TV) and played inside your level.

For this how-to, we use Unreal Motion Graphics (UMG) to create a UI element that will play a streamed video fullscreen.

StreamSourceHero.png

Steps

For this how-to we are using the Blueprint Third Person Template project with Starter Content enabled.

  1. In the Content Browser expand the Sources Panel and create a new folder called Media inside the Content folder.

    StreamMedia_01.png

  2. Right-click inside the empty Media folder, then under Media, select Stream Media Source and name the asset MediaStream.

    StreamMedia_02.png

  3. Open MediaStream then enter your desired Stream URL.

    StreamMedia_03.png

    If you do not have a URL file to link to, right-click this Sample Video and copy the link address and paste it in the Stream URL field.

    Your Stream URL must link directly to a supported format in order to play the video. For example, PS4Media (PS4) only supports MP4 through HLS in the latest engine version, while WmfMedia (Windows) can support a number of other stream sources. For further information on supported formats per platform/player plug-in, see the Media Framework Technical Reference page.

  4. Right-click inside the Media folder, then under Media, select the Media Player asset.

    StreamMedia_04.png

  5. In the Create Media Player window, enable Video output Media Texture asset then click Ok.

    StreamMedia_05.png

    This will automatically create and associate a Media Texture asset linked to this Media Player asset which is needed for playback.

  6. Name the new Media Player Asset MyPlayer which will automatically be applied to the created Media Texture asset.

    StreamMedia_06.png

  7. Right-click in the Media folder, then under User Interface select Widget Blueprint and call it HUD.

    StreamMedia_07.png

    A Widget Blueprint is an asset that is used with UMG UI Designer to create UI elements within Unreal Engine 4 which we will apply our streaming video to.

  8. Inside the HUD Widget Blueprint, from the Palette window drag an Image into the graph and stretch it to fill the grid's aspect ratio.

    StreamMedia_08.png

    We are going to apply our Media Texture to this image, and the image will fill the player's viewport when playing the game (creating a video that will play fullscreen).

  9. In the Details panel for the Image under Appearance expand Brush then set the Image to MyPlayer_Video.

    StreamMedia_09.png

  10. In the Details panel for the Image under Slot, click the Anchors dropdown and select the anchor middle option.

    StreamMedia_08b.png

    This will ensure that the image stays fixed in the center of the viewport regardless of viewport size.

  11. Close the HUD Widget Blueprint, then from the Level Editor Toolbar, select Blueprints and Open Level Blueprint.

    StreamMedia_10.png

  12. Create a new variable called MediaPlayer of the Media Player Reference type and set the Default Value to your MyPlayer Media Player asset.

    StreamMedia_11.png

    You may need to click Compile in order to see the Default Value of your MediaPlayer variable.

  13. Hold Ctrl and drag the MediaPlayer variable into the graph to create a Get node for this variable, then right-click and add an Event Begin Play node.

    StreamMedia_12.png

    When our game starts, we will go through the process of creating and displaying our HUD, set up sound for our stream, then open our stream so that it plays.

  14. Right-click and add a Create Widget node and set Class to HUD, then off the Return Value use Add to Viewport and connect as shown.

    StreamMedia_13.png

  15. Following the Add to Viewport node, right-click and use Add Media Sound Component and set the Media Player to MyPlayer in the Details panel.

    StreamMedia_14.png

    In order to hear audio along with your video, you will need to use a Media Sound Component which points to your Media Player asset. Here we are dynamically creating and adding one at runtime. However, you can also add this component to an Actor that exists in the level or as part of a Blueprint from the Components panel.

  16. Following the Add Media Sound Component node off the Media Player reference node, use Open Source and set Media Source to your MediaStream asset.

    Click image for full view.

    With our node network complete, when the game starts our HUD will be created and displayed, and sound will play along with our Media Stream we open it for play.

  17. Close out the Level Blueprint, then click the Play button to play in the Level.

End Result

After playing in the Editor, the video will start playing back in full screen as part of our HUD Widget Blueprint.

Similar to using a File Media Source which plays a video file from disk, Stream Media Sources will automatically play when calling Open Source if their associated Media Player asset are set to Play on Open which by default is enabled. There are additional commands you can issue to the Media Player asset such as pausing, rewinding or stopping the video once it has begun playing which can be found under the Media Player section when dragging off the Media Player Reference.