首页 > 解决方案 > 如何在 Android 中使用 `MediaElement` 播放声音?

问题描述

MediaElement用来在 Uno-Platform 项目中播放声音。

它在 UWP 项目中运行良好,但在 Android 项目中不起作用。

音频文件作为Exclude from project位于共享项目中,在 UWP 项目中链接为Content,在 Droid 项目中链接为AndroidAsset

XAML:

<MediaElement Source="/Assets/MySound.wav"/> 

我也尝试过以编程Source方式访问它,但ms-appx:///Assets/MySound.wav没有成功。

标签: androiduwpuwp-xamluno-platform

解决方案


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


推荐阅读