Answer the question
In order to leave comments, you need to log in
Playing network MP3 stream in .NET 6?
Recommend an example in C# or a framework/library for connecting and playing streaming audio from the network that is compatible with .Net 6 (MAUI application). Tried BASS (net api), NAudio, nothing compiles with 6th version of .NET.
Answer the question
In order to leave comments, you need to log in
The BASS library is not complicated, especially since it works on all common platforms. Write your wrapper, there is nothing complicated. Here is an example:
!ALERT! I only coded hello worlds in C# about 10 years ago, so I'm not familiar with .NET, but I'm familiar with this library. This example needs to be reworked, since I stupidly made all the parameters except string and bool roughly int. This example was just made in .Net 6 on Linux. Therefore, you need to throw the BASS library for your platform into the folder with the executable file.
using System.Runtime.InteropServices;
class MyApp
{
[DllImport ("bass.so")]
// BOOL BASS_Init(int device, DWORD freq, DWORD flags, HWND win, void *clsid);
public static extern int BASS_Init(int device, int freq, int flags, int win, int clsid);
[DllImport ("bass.so")]
// HSTREAM BASS_StreamCreateURL(char *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, void *user );
public static extern int BASS_StreamCreateURL(String url, int offset, int flags, int proc, int user );
[DllImport ("bass.so")]
// int BASS_ErrorGetCode();
public static extern int BASS_ErrorGetCode();
[DllImport ("bass.so")]
// BOOL BASS_ChannelPlay(DWORD handle, BOOL restart);
public static extern bool BASS_ChannelPlay(int handle, bool restart);
[DllImport ("bass.so")]
// BOOL BASS_ChannelSetAttribute(DWORD handle, DWORD attrib, float value);
public static extern bool BASS_ChannelSetAttribute(int handle, int attrib, float value);
static void Main()
{
int bass_init = BASS_Init(-1,44000,0,0,0); // Инициализируем библиотеку BASS;
int hstream = BASS_StreamCreateURL("https://online.rusradio.ua/RusRadio",0,0,0,0); # Создаем поток из url;
BASS_ChannelSetAttribute(hstream, 2, 0.1f); // Устанавливаем громкость. 3 параметр громкость в float, 1f = 100%, 0.1f = 10%
// int err = BASS_ErrorGetCode(); // Функция для получения кода ошибки. Коды ошибок в bass.chm
// Console.WriteLine(err.ToString());
BASS_ChannelPlay(hstream, false); // Запускаем проигрование потока
Console.Read(); // Без этой строки консольное окно сразу закроется и программа завершится.
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question