0

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,

5
  • 1
    Consider downloading the mp3 file in FileSystem.Current.AppDataDirectory folder and then use FileSystem.OpenAppPackageFileAsync(mp3) to play it. Commented Dec 25, 2023 at 6:59
  • Thank you Alexander. Merry Christmas. Unfortunately I tried using FileSystem.Current.AppDataDirectory to download the mp3, but I still have the same problem,. File.Exists("/data/user/0/com.companyname.myapp/files/Download/2015-06-28_AM.mp3"); returns true,, but FileSystem.OpenAppPackageFileAsync("/data/user/0/com.companyname.myapp/files/Download/2015-06-28_AM.mp3") Returns file not found exception.. Commented Dec 25, 2023 at 20:51
  • Merry Christmas too! Are you downloading the file in the android emulator or the real device? If so, can you try to save the file in the external storage? See stackoverflow.com/a/73469775 Commented Dec 26, 2023 at 9:41
  • Hi There. I have tried on both emulator and physical device. Both return System.IO.FileNotFoundException: '/data/user/0/com.companyname.myapp/files/Downloads/sermon.mp3' but: File.Exists(FileUri) (where FileUri is the path to mp3) returns true. I have tried using Plugin.Maui.Audio;, and var player = AudioManager.Current.CreatePlayer(await FileSystem.OpenAppPackageFileAsync(filePath)); player.Play(); this fgives same file not found exception. Commented Dec 29, 2023 at 22:56
  • also used: string downloadsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); to get dir. Which resolved to /data/user/0/com.companyname.myapp/files Commented Dec 29, 2023 at 23:04

1 Answer 1

0

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. 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.