How to play an OGG file at runtime without having to import it?

How do you simply play an OGG music file at runtime, without having to import it? I want the players to be able to play their own music in the game.

There should be a simple Blueprint Function:

PlayOGGFile(FilePath)
StopOGGFile(FilePath)

Or something like that.

1 Like

Unreal’s built-in Media Player should be able to handle it; specifically, I’d look at the Open Source (to open a media file), and Play (to, well, play said file) nodes.

While the documentation on Media Player is a little slim, a quick journey to the universal global helpdesk (i.e., Google) turned up what at first glance looks like a reasonably nice tutorial on streaming media in-game.

I only skimmed it, admittedly, but I’d imagine even if it’s not enough to get you where you’re trying to go entirely (especially since it focuses on streaming video), it’s probably at least a starting place for working with Media Player.

2 Likes

This works perfectly! Didn’t know the media player could play sound files! Even works for URLs!

To play local files that the user can choose at runtime, use Open File. Open Url works at runtime, too. You’ll probably also want to bind On Media Opened & On Media Open Failed so you know when the media is opened.

Though, I tested it on a few ogg files, and it didn’t work (it did for mp3 & wav). I’m on 4.20. If you can’t get it to work for you, Rama’s plugin and RuntimeAudioImporter can play ogg.

2 Likes

Yeah, I should probably have also mentioned the CanPlayURL node, which will check if it’s a media file that’s usable or not.

Still, that the Media Player doesn’t natively support ogg doesn’t entirely surprise me, especially as far back as 4.20; it’s mildly disappointing, granted, but not all that surprising.

1 Like

I had problems getting this to work from the UMG UI. After you add this code, you have to follow instructions in the link below. I give a quick and dirty explanation.

EDIT: You have to follow the instructions here: Upgrading Media Framework Content to 4.18 | Unreal Engine Documentation

In order to use media player from UMG UI, you have to add the Media Sound component to an object in your scene. So click a wall for example, click add component, choose Media Sound in the drop down, then select the Media player you added in your folder. Then use the above code and it will work.

2 Likes

I’m finding that changing the volume of the media player is impossible. I can’t figure out how to do it.

Do you know how to change it’s volume using a Music Sound Mix class for example?

1 Like

You can use Set Volume Multiplier. You call it on the media sound component.

1 Like

Okay, I got the volume multiplier to plug in, but it still doesn’t work, no matter if I set it before or after. Here’s my code. This is from the level blueprint.

The music mp3 file plays, but I have no volume control.

I assigned the media sound component from the level to the Music Sound Class, but the Music Slider volume control doesn’t work; it only works for music played normally outside the media player.

1 Like

FYI, I made a new post with more detailed information. I still can’t get the volume control to work. I post this as a courtesy since you seem to be genuinely interested in this, thanks!

1 Like

Hey,

If you want to import an audio file so that it is presented as an engine sound wave, then there is a free plugin for this: Runtime Audio Importer.

It supports all the features that a standard sound wave supports, including dynamic volume change.

1 Like