How to use `MediaElement` to play sound in Android

2019-05-30 23:36发布

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.

2条回答
混吃等死
2楼-- · 2019-05-31 00:22

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).

查看更多
神经病院院长
3楼-- · 2019-05-31 00:27

MediaPlayerElement is now available in Uno (See MediaPlayerElement documentation)

查看更多
登录 后发表回答