Like in title. How can I play audio file using CoreCLR?
Are there plans for support cross-platform audio playing in the future?
Hey @czesiu it's an interesting question and I have to admit that I don't know the answer, but I did a bit of hunting to find out, and I suspect that answer is "no for now, probably in future". Though I'd also suspect that even the "no" might be supported by a third party somewhere.
If you look at the stack overflow answers for "how do I play sound with C#" you see people talking about the System.Media namespace:
and if you go into the dotnet API reference you see that system.media isn't there yet:
If you search the dotnet forums for Audio - you get a couple leads in terms of third party products that might be worth looking at in more detail: https://github.com/reignstudios/ReignSDK
And you can also look towards UNITY (perhaps)
If I start to dig around a bit more, things start to get hazier. Sorry I can't be more help. It's an interesting question.
Right now, there's no "high-level" API for audio playback. If you are adventurous, you can try things like OpenTK, which expose lower-level OpenAL functionality. This will be much more difficult than something ready-to-go like System.Media.SoundPlayer, but will be cross-platform and much more flexible.
Disclaimer: I've never tried to use the OpenAL functionality of OpenTK on .NET Core. I've only used the graphics portions of the library.
I did own research and I found following libraries/solutions:
System.Media.SoundPlayer to play ogg files.Here's stack overflow question with some of this libraries mentioned: http://stackoverflow.com/questions/35896/how-can-i-play-compressed-sound-files-in-c-sharp-in-a-portable-way
I tested only BASS.NET and ManagedBass and they are working with .NET Core on Mono.
Most of these C# libraries are only P/Invoke bindings to some multiplatform C library. I like ManagedBass because it has PCL library which is .NET Core compatible (DNX and DNX Core environments). BASS.NET (and probably other mentioned libraries) have only full .NET version, so I can run it only with #if DNX451 switches and only in Mono runtime. With PCL ManagedBass I have code without #if DNX451 switches which compiles properly for DNX and DNX Core version.
But there is one issue in DNX Core, from which reason I can run ManagedBass only on Mono. This issue is related with name of P/Invoked library. Binding in PCL library looks like that:
[DllImport("bass", EntryPoint = "BASS_Start")]
public static extern bool Start();
and because this is a PCL, then name of library in a code must be same for all platforms. But library name in various platforms is different, e.g. "libbass.so" in Linux and "bass.dll" in Windows.
Mono has automatic library mapping mechanism described here (there is also manual mechanism described here).
Is there similar mechanism in DNX Core runtime or do you have plans for adding it?
Do you have plans for adding DllMap (automatic or/and manual) mechanism in CoreCLR?
@czesiu Maybe ask in a new issue.
Most helpful comment
I did own research and I found following libraries/solutions:
System.Media.SoundPlayerto play ogg files.Here's stack overflow question with some of this libraries mentioned: http://stackoverflow.com/questions/35896/how-can-i-play-compressed-sound-files-in-c-sharp-in-a-portable-way
I tested only BASS.NET and ManagedBass and they are working with .NET Core on Mono.
Most of these C# libraries are only P/Invoke bindings to some multiplatform C library. I like ManagedBass because it has PCL library which is .NET Core compatible (DNX and DNX Core environments). BASS.NET (and probably other mentioned libraries) have only full .NET version, so I can run it only with
#if DNX451switches and only in Mono runtime. With PCL ManagedBass I have code without#if DNX451switches which compiles properly for DNX and DNX Core version.But there is one issue in DNX Core, from which reason I can run ManagedBass only on Mono. This issue is related with name of P/Invoked library. Binding in PCL library looks like that:
[DllImport("bass", EntryPoint = "BASS_Start")]public static extern bool Start();and because this is a PCL, then name of library in a code must be same for all platforms. But library name in various platforms is different, e.g. "libbass.so" in Linux and "bass.dll" in Windows.
Mono has automatic library mapping mechanism described here (there is also manual mechanism described here).
Is there similar mechanism in DNX Core runtime or do you have plans for adding it?