bestvcboy
Topic Author
Posts: 2
Joined: 09 Apr 2022, 18:05

MediaElement can't play in Unity?

12 Apr 2022, 16:13

<MediaElement Source="G:\\test\\UnityApp1\\UnityApp1\\Assets\\Narrator107.mp3" LoadedBehavior="Manual" Name="media1">
</MediaElement>


var media = FindName("media1") as MediaElement;
media.Play();

I tested it. MP4 can play, but MP3 and wav can't play at present. Can this play?
 
simonb
Posts: 24
Joined: 22 May 2021, 16:35

Re: MediaElement can't play in Unity?

14 Apr 2022, 17:44

Had the same issue trying to play wav audio files.
Needed to use a MediaElement as I wanted to receive an event when the the audio stopped playing.

In the end I found the best solution was to convert all the wavs into mp4 files, using 'ffmpeg' (which is all round excellent & batch converts very easily)
If you use Unity though, you will need to convert them into actual video mp4s - when I converted I added add a parameter to insert a redundant single black frame.

Works fine after that and the mp4s are smaller than my Wavs!
(Its speech so it really doesn't affect anything for the purists out there) :)
 
User avatar
jsantos
Site Admin
Posts: 4823
Joined: 20 Jan 2012, 17:18
Contact:

Re: MediaElement can't play in Unity?

14 Apr 2022, 21:11

<MediaElement Source="G:\\test\\UnityApp1\\UnityApp1\\Assets\\Narrator107.mp3" LoadedBehavior="Manual" Name="media1" />
Absolute paths like this are not correct in Unity as you shouldn't use resources out of the project. As described in the URI documentation the correct ways to use an absolute or relative path are:
<MediaElement Source="Narrator107.mp3" LoadedBehavior="Manual" Name="media1" />
<MediaElement Source="/Assets/Narrator107.mp3" LoadedBehavior="Manual" Name="media1" />
Also note that in Unity we are using the underlying media player, so we can only be compatible with formats supported by Unity itself.

Who is online

Users browsing this forum: No registered users and 2 guests