Plugin.Maui.Audio 不播放本地文件

问题描述 投票:0回答:1

我已经问过这个问题,但我认为这个简化版本更好地解释了问题,

在.net 7.0 maui应用程序中,使用Plugin.Maui.Audio,我使用以下代码尝试播放本地mp3文件(已下载)

filePath = "/data/user/0/com.companyname.myapp/files/1.mp3";
var player = AudioManager.Current.CreatePlayer(await FileSystem.OpenAppPackageFileAsync(filePath));
player.Play();

返回:

System.IO.FileNotFoundException: '/data/user/0/com.companyname.myapp/files/1.mp3'

在 Visual Studio 2022 中构建并在 Android 模拟器或物理三星 Android 设备上运行时。

该文件确实存在,如下所示:

File.Exists(sermon.FileUri)
返回真

我也尝试过:

filePath = "file///data/user/0/com.companyname.sermonsearch/files/1.mp3";
var player = AudioManager.Current.CreatePlayer(await FileSystem.OpenAppPackageFileAsync(filePath));
player.Play();

同样的错误。找不到文件。

此外,如果我使用 adb shell 将文件 1.mp3 复制到本地电脑,它可以像 mp3 一样正确播放,所以文件是好的!

maui mp3
1个回答
0
投票

这个问题现在已经解决了。我使用 CommunityToolkit.Maui.MediaElement Mediaplayer MyMediaPlayer.Source = MediaSource.FromFile(""/data/user/0/com.companyname.myApp/files/Download/2012-05-06_AM1.mp3");

And this works perfectly.
© www.soinside.com 2019 - 2024. All rights reserved.