I have a .net maui app, (.Net 7) which downloads mp3 files, to "/data/user/0/com.companyname.myapp/files/Download"
I have tried to play them back using a webview:
<audio controls>
<source src="/data/user/0/com.companyname.myApp/files/Download/2012-05-06_AM1.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio controls>
Which does not work, as the play arrow is just Greyed out.
also tried prefixing file with : src="file///data/user/0/ ....
That does not work either.
If I try
if (File.Exists("/data/user/0/com.companyname.myApp/files/Download/2012-05-06_AM1.mp3" ))
{
Shell.Current.DisplayAlert("Found", "File Exists", "OK");
}
The file is found,
I have also tried using the following function, and passing the file ref in the mp3 parameter:
private async void MyPlayer(string mp3) {
var audioPlayer = AudioManager.Current.CreatePlayer(await FileSystem.OpenAppPackageFileAsync(mp3));
audioPlayer.Play();
}
This also errors with file not found.
Any Ideas would be appreciated. This is very frustrating.
If I use a https url, it all works fine. Just when using a local file. I want the app to be able to play downloaded files, when offline,
This is now resolved. I used 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.