Im working on something similar to the game audio surf. Is there a way i can open a window to choose a file and upload it to the game whilebits running?
In UE4 code, no. But you can code it yourself, but only in C++. The old audio system has GeneratePCMData which allows to pipe in any PCM sound data, but it very funky and sometimes act wierd:
New audio system is a lot easier to pipe in any sound data, but i yet to explore it, look up the synth demo plugin.
In either solution you will need to decompress audio data to PCM (or else you gonna use raw audio data which is overkill ;p), UE4 doesn’t provide mp3 support due to licencing issues (use of it requires paying royalties, you too better watch out on it, it’s number one reason why you see ogg more in games), only Vobis ogg decoding is somewhere in engine, i didn’t explore that either.
Yes, you can do this, and you don’t need C++ (just blueprints).
- In the content browser, create a “Media Player” and a “Stream Media Source”. (Leave the “stream url” of the “Stream Media Source” empty.)
- Create an actor blueprint and open it.
- Create a variable of type “Stream Media Source”. In the “Details” panel on the right, select the default value for “Audio Media Source” as the asset you created in step 1.
- In the “Components” pane of the blueprint (upper left corner), use “Add Component”, “Media Sound”.
- Select the newly created media sound, and in the “Details” panel on the right, under “Media”, select your Media Player asset that you created in step 1.
- In the “My Blueprint” pane, under Variables/Components, drag the media sound into the event graph and chose “get”.
- From this node, drag and search for “Get Media Player”.
- Create a variable of type Media Player. Drag it into the event graph and select “set”.
- From the “BeginPlay” event, set your Media Player variable from the “Get Media Player” node
- When you’re ready, get the input filepath to the audio file by whatever means you choose.
- Use the Utilities/String/Replace node to replace all backslashes with forward slashes in the filepath.
- Prepend the filepath with “file://” using the String/Append node.
- Drag the Stream Media Source variable into the graph with “get”, and drag off of that and search for “set stream url”. Set the url with the string that now begins with “file://”.
- Optionally, use the Media/MediaPlayer “Can Play Source” node (along with the Media Player variable and the Media Source variables) to validate the audio file.
- When you are ready to play the audio, use the Media/MediaPlayer “Open Source” node (along with the Media Player variable and the Media Source variables) to begin playing the audio.
One major disadvantage I’ve run into is that the Media Player “Get Time” node is sometimes inaccurate. (Unlike AudioComponent’s OnAudioPlaybackPercent, which is always accurate).
Actually, I was able to get accurate playback time from the Media Player by using
Project Settings → Plugins → WMF Media → Media → Allow Non-Standard Codecs ;
Project Settings → Plugins → WMF Media → Media → Low Latency ;
Project Settings → Plugins → WMF Media → Debug → Native Audio Out ;
and then pressing “set as default” and restart UE4.
Hey Preston, I love you!!! I was beating my head around this issue, tried your advice and it worked. YOU ARE THE GOAT!!!
Heya, could you explain how did you proceed from the “when you are ready, get the input filepath to the audio file by whatever means you choose”?