问题
I'm using MediaElement
to play sound in an Uno-Platform project.
It plays well in the UWP project but doesn't work in the Android project.
The audio file is located in the shared project as Exclude from project, and is linked in the UWP project as Content
and in the Droid project as AndroidAsset
.
XAML:
<MediaElement Source="/Assets/MySound.wav"/>
I've also tried accessing it programmatically set the Source
to ms-appx:///Assets/MySound.wav
with no success.
回答1:
MediaPlayerElement
is now available in Uno (See MediaPlayerElement documentation)
回答2:
As of today, local resources are not supported for iOS in the the Windows.Media.Playback.MediaPlayer
class, but adding support for it should be relatively easy.
On Android, it should work, but there's probably another issue, related to the name of the asset, such as casing (android is lower case) or hyphens (transformed to '_' by android).
来源:https://stackoverflow.com/questions/52919882/how-to-use-mediaelement-to-play-sound-in-android