dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.99k stars 1.72k forks source link

Framework for audio playback #7152

Open dawidpieper opened 2 years ago

dawidpieper commented 2 years ago

Description

Currently, Maui does not have any audio playback framework. Implementing such an API is relatively simple. However, I noticed that in places like Stackoverflow there are many examples for Xamarin that have memory leaks and other bugs for various reasons. I know that now, when we are approaching the release, it is quite late to add such a large interface, but I think that it is worth considering as part of long-term plans in order to systematize some assumptions.

API content

I think the first step should be classes that allow to:

Then we might consider adding:

The most important difficulties

Windows, iOS, Mac, and Android all have different sets of audio formats supported by default. For example, iOS does not natively support the OGG format. Interfaces returning a list of supported codecs / containers and good documentation would be necessary.

If this proposal is accepted, I will gladly implement it.

Public API Changes

We should add custom interface, something like Microsoft.Maui.Media.Audio

Intended Use-Case

Many apps use simple audio for informing users about in-app events. Implementing that option in Maui would simplify the work needed and encourage more developers to use this.

jcmontoya commented 2 years ago

.Net MAUI is in RC Status. in my opinion not having any supported sound library should be addressed. We can use essentials to play a sound using the launcher functionality. But if all I need is a beep in my app, that is not really a good user experience. I know there is already some ideas in the pipeline, but Sound and Media (Camera/Scanner) is a must for all platforms... at least in today's world.

Codingale commented 2 years ago

I'm a beginner in Xamarin/Blazor and not having a easy way for media playback built-in is confusing. The only way I could find was using Blazor and using a audio tag and invoking the Play method which is really complicated for a beginner and felt like a hack instead of a solution to me,

Adding onto that it seems like there's a lot of want for this but no clear action being taken? I could just be very far out of the loop and missing something simple and it's actually very easy to play simple ogg files in my tests and I just missed it but it seems like there's a whole rabbit whole for something like this at least: https://github.com/CommunityToolkit/Maui/issues/113

Edit as stated I'm a beginner and unfamiliar with many of iOS' many joys, implementation is entirely speculative currently if at all and I was merely voicing support and giving examples for examples.

dawidpieper commented 2 years ago

Using HTML <audio /> tag has some limitations. iOS is a particular problem as Apple Webkit cuts longer audio recordings that are played using this tag. We are talking here about recordings counted in minutes, but it is an obstacle worth remembering.

dawidpieper commented 2 years ago

By the way, iOS does not have support for OGG container nor Vorbis codec. It could be implemented in Maui, but I don't see a reasonable reason for linking OGG Vorbis here. So we could focus on MP3, WAV and AAC as suggested audio formats. If support for OGG, OPUS, FLAC or other codecs is needed, I would recommend linking them in project itself.

JoeGilkey commented 2 years ago

This could be done thru the Community Toolkit. Create platform specific implementations of IWavePlayer from NAudio for playback, and use NLayer or NVorbis for Mp3 and OGG files respectively.

apws commented 2 years ago

Hi @JoeGilkey isnt entire NAudio in C# NET2.0 ? Ahh, you mean only take source code and port it to net-core / net6?

I am also finding way how to play MIDI files crossplatform way. In java, there is complete JavaSound MIDI + Gervill DLS softsynth runnable on win/mac/linux. For now, I found multiplatform C FluidSynth SF2 syntheizer, (win/mac/lin+android) to which could be easy to connect as MIDI device from MAUI app - it can even serve as simple audio notification then.

vhj1995 commented 1 year ago

When this is planned for release?

ToolmakerSteve commented 1 year ago

Unfortunately there is no mention of audio in https://github.com/orgs/dotnet/projects/194/views/2.

I think that means there is no plan yet.

ghost commented 1 year ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

jones-web-consulting commented 1 year ago

This is a needed feature. There are tutorials on YouTube (eg. https://youtu.be/3jcVYUE-Tww) featuring MSFT employees such as @jamesmontemagno demonstrating the creation of games. While MAUI wouldn't be a good solution for most games, basic games, such as card games could be developed using .Net MAUI. Even with these videos describing the creation of real-time games, there is no way to play sounds within .Net MAUI. Without the ability to play sounds, using MAUI for basic games is not practical. Games require sounds. There's no reason why .Net MAUI couldn't work as a solution for 2D games, like Solitaire.

jeremy-visionaid commented 10 months ago

Shout out to @jfversluis for the excellent third-party offering on this front: https://github.com/jfversluis/Plugin.Maui.Audio http://www.nuget.org/packages/Plugin.Maui.Audio Made basic audio playback a breeze, thanks! 🥇

jfversluis commented 10 months ago

Hey all, there is indeed no audio playback on the roadmap as of yet. Hence why it is still in the backlog.

Keep in mind, .NET MAUI is still primarily a UI framework. There is so many things we can add to .NET MAUI and I'd love to have it all, but we have to make some (tough) choices on where to spend our time. We're continuously monitoring your feedback though and determine our priorities based on that.

As @jeremy-visionaid pointed out, I did see the need for this functionality and provided a plugin for the meanwhile, so please see if that fits your needs.

Thanks for all the input!