Skip to content

Allow audio playback from any path on Windows #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

t871005y
Copy link
Contributor

I noticed that audio files only located under "Assets" can be played on Windows platforms using the following API.

public AudioPlayer(string fileName, AudioPlayerOptions audioPlayerOptions) { }

player.Source = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/" + fileName));

Maybe we can use the fileName directly to play audio, enabling users to play audio from any location(Recordings saved in FileSystem.AppDataDirectory, for example).

@bijington
Copy link
Collaborator

Thank you for the PR. I like the change but I want us to make sure we clearly highlight the breaking nature of this

@jfversluis
Copy link
Owner

Is there any way we can come up with a way to have an option to toggle this? Or a migration path? To make it not breaking/less breaking?

@bijington
Copy link
Collaborator

I've been trying to think on this. I might have an idea which I'll try and write up shortly.

@bijington
Copy link
Collaborator

The least breaking option that I can think of is to introduce a new property AudioPlayerOptions for windows that lets developers control this path behaviour and default the setting to the current behaviour. I don't know if this is a good long term option though, what do you think?

For now developers can play file from any path but they need to use the CreatePlayer(Stream audioStream) method instead and pass in a FileStream

@t871005y
Copy link
Contributor Author

I remember having memory issues on Android before because the code was loading the audio stream completely into memory.

if (OperatingSystem.IsAndroidVersionAtLeast(23))
{
using var memoryStream = new MemoryStream();
audioStream.CopyTo(memoryStream);
audioBytes = memoryStream.ToArray();
}

Therefore, if I need to play large audio files and support all platforms, I prefer using the load from path API over the load from stream API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants