mobiletechtracker / netcoreaudio Goto Github PK
View Code? Open in Web Editor NEWAllows playback of audio files on .NET Core with minimal dependencies
License: MIT License
Allows playback of audio files on .NET Core with minimal dependencies
License: MIT License
Does it support playback audio on Android & IOS ? specifically "mp3" ?
Instead of only Files.
It would be great if the player had a way to set the volume. This would also allow users of the library to build things like fade-in and fade-out or crossfade between different tracks.
I would have made a PR if I could test for linux and mac, but I did throw something together that works on windows:
[DllImport("winmm.dll")]
private static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);
[DllImport("winmm.dll")]
private static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);
public int GetVolume()
{
var result = waveOutGetVolume(IntPtr.Zero, out var v);
if (result != 0)
throw new Exception($"Error executing command 'waveOutGetVolume'. Error code: {result}.");
var volume = Math.Min(100, v * 100 / ushort.MaxValue);
return (int)volume;
}
public void SetVolume(int volume)
{
var v = (uint)(ushort.MaxValue * Math.Max(0, Math.Min(100, volume)) / 100.0);
var result = waveOutSetVolume(IntPtr.Zero, v);
if (result != 0)
throw new Exception($"Error executing command 'waveOutSetVolume'. Error code: {result}.");
}
It always takes the first audio device (IntPtr hwo
) - I don't know if this is always correct and it would probably not scale to playing multiple sounds simultaneously but it worked for me. Another thing to note is that if you get the volume without ever having set it, then it will return uint.MaxValue (or something close to it), but my code just converts it to max volume which I think is correct.
it's not possible to read music from file that contains spaces in path
Is there any way this could support recording audio from a microphone?
I need to play an mp3 in a loop. Is this behavior supported?
Hi,
I have try to implement the volume control for linux and I have the error amixer: Unable to find simple control 'Master',0
, I know why, I don't have a Master
but on your code, for linux var tempProcess = StartBashProcess($"amixer -M set 'Master' {percent}%");
you specify on it the Master
Can you take on argument of Player
ctor, in case of linux, the control interface and by default Master
?
Regards
I get an error whenever trying to run the line
Player.Play(filePath).GetAwaiter().GetResult();
Error
Error executing MCI command 'Status C:\Users\Panda\source\repos\TextToSpeechApi\TextToSpeechApi\bin\Debug\netcoreapp2.1\Voices\testing sound.mp3 Length'. Error code: 310. Message: Specify a device or driver name that is less than 79 characters.
Wasn't sure if this was the same error that has already been posted considering the Error code is different...
Platform: Windows
Steps to reproduce:
Expected behaviour:
PlaybackFinished event should be raised when audio stops.
Actual behaviour:
After PlaybackFinished event is raised, audio still plays for 1 or 2 seconds.
Code example:
Player player = new Player();
player.PlaybackFinished += (sender, args) =>
{
// This event is triggered even if the player still has 1 or 2 seconds to play.
};
player.Play(path);
Whenever I try to use SetVolume before or after calling play or pause, my app freezes. Also, pause makes the sound sort of repeat on a small bit of audio over and over.
I am using the sound component to play a sound in a game when a person makes the wrong selection. The button is attached to an eventhandler that plays the error sound file(about 1 second of audio) with player.play(). If the person presses the wrong button quickly it will crash with a few different errors using the following code:
if (player.Playing || player.Paused)
{
await player.Stop();
}
await player.Play(fileName);
Mainly with Object reference not set to an instance of an object.' on the stop command. or with 'Error executing MCI command 'Close All'. Error code: 288. Message: The specified device is now being closed. Wait a few seconds, and then try again.' on the play command.
Is there a better way to do this? Is there any way to reuse the connection and play different sounds without having to destroy the object and restart it every time which seems to be causing the problem here?
I have only tested this on Windows but the application will run on both windows and Linux(Raspberry Pi).
It would be nice if there was a way to configure the library to not write debug logs to the console for small console applications. Otherwise a great project.
As a .NET Core developer, I've been struggling to read audio from a mp4 file. Why would you ask? Well, I've been trying to basically play mp4 files and, while that's working, I can't seem to be able to get audio to work for some reason.
So now I'm using this library (which works great) to load in a different file (an mp3 extracted from the mp4), but I'd love to have support for mp4 files too!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.