i am using Windows Multimedia API winmm.dll library to play MP3 files and when i load a song it takes kins of 3-5 seconds to open and start the song . I wish to make a music app and that requires fast loading. Any ideas how i can improve the code ?
Here is the code i've used : http://www.geekpedia.com/code111_Play-MP3-Files-Using-Csharp.html
Regards,
Alexandru Badescu
I am not an audio/video expert but from my experience it's very limited in managed code. You either have to get into the win32 API or go the DirectX route. DirectSound cannot play mp3 files natively. You will need to use DirectX if you don't like the win32 PInvokes response times.
You will need the DirectX SDK and then import the audio video playback namespace.
Imports Microsoft.DirectX.AudioVideoPlayback
You can then use the directx objects to play an mp3 file.
Have you looked at this?
http://www.robburke.net/mle/mp3sharp/
He claims to have a sample, using DirectSound where he plays the MP3.
Related
My goal is to mix 2 audio files that is one voice and one background music. For mixing I am using NAudio.
The problem is I am getting following exception while reading mp3 file using NAudio's Mp3FileReader.
DllImport cannot be used on user-defined methods
I am using NAudio in Windows Phone 8.1 Silverlight app project. I am not sure if NAudio is useable on WP Silverlight app if its useable then please help by providing a code example or suggest any other library or custom implementation to mix 2 audio files.
No, I'm afraid NAudio is not usable on Silverlight, as it makes lots of calls into Windows APIs which you can't do in Silverlight. You can take a look at the NAudio NLayer project which offers fully managed MP3 decoding. You could use that in conjunction with some of the more generic helper classes in NAudio like the MixingSampleProvider to perform the mixing you require. Of course the next issue would be what you want to do with that mixed audio. Silverlight does have a way of streaming user generated audio using the MediaElement but NAudio does not provide support for this directly.
[DllImport] requires a substantial chunk of code in the CLR, nothing very subtle about the pinvoke marshaller. That's a problem on a phone, it runs a special version of the CLR named .NETCore. Probably better known today as the codebase that spun-off the CoreCLR open source project. Keeping it small required unsubtle choices, pinvoke fell on the floor.
So no, you'll have no use at all for NAudio. You'll have to dip into the built-in support for audio. The relevant oversight MSDN page is this one. This blog post is relevant.
As you can tell, XAudio2 is your ticket with direct support for mixing. There is a learning curve of course, the language is probably the first obstacle given the question tags. Get started with this sample to get the basics.
Maybe you should consider taking the step to upgrade from WP8.1 Silverlight (WPS) project to WP8.1 (WinRT) one so that you have better access to audio APIs...
...or directly to a UWP/Win10 app (if you don't plan to release immediately to phones). If you choose that path, you could try maybe a free preview tool that converts WPS to UWP, just released from Microsoft and Mobilize.NET - https://blogs.windows.com/buildingapps/2015/09/17/initial-preview-of-silverlight-bridge-to-uwp/
I am looking for a effective way to compress a real time video stream. In my project, the streaming seems important because my system will send and receive both the audio and video streams at the same time. I am considering using H261 or H263. How can I achieve such compression ratio using C#?
PS I found something called H323Plus, but I do not know how to call this library because it is written in C++.
If you want to do real-time streaming over UDP with both audio and video stream you can use the DirectShow API (if you're targeting Windows).
http://msdn.microsoft.com/en-us/library/windows/desktop/dd375454(v=vs.85).aspx
You will find a .NET wrapper for DirectShow here
http://directshownet.sourceforge.net/
You will also find more samples on codeproject.com, most of them use this wrapper
http://www.codeproject.com/kb/audio-video/#DirectShow
If you plan on targeting Windows 7 and newer only, then you will want to use Windows Media Foundation API
http://msdn.microsoft.com/en-us/library/windows/desktop/ms694197(v=vs.85).aspx
I want to capture sound from mic and play it again in speakers in c# but not using Microsoft.DirectX.directsound how?
As an alternative to DirectSound there are the multi-media APIs. I know of no binding that's included with .net, but there are several third party bindings of varying quality.
naudio is a popular .net audio library, but I don't know which API it uses in the background. As long as you avoid the abomination called WaveBuffer you should be fine.
In my project I used Lumisoft.Audio, mainly because it has a simple API. But their code doesn't have a very high quality.
As CodeInChaos mentions NAudio (http://naudio.codeplex.com/) will do the trick. Here is an article from channel 9, which hopefully will help you out:
http://channel9.msdn.com/coding4fun/articles/NET-Voice-Recorder
This is from Mark Heath's NAudio demo (http://voicerecorder.codeplex.com/) as he mentions in this other post: Capture a Microphone Audio Stream Using .NET Framework
Is it possible to use the NAudio on a silverlight application?
I just can't add the dll to my project... I'd like to build a little audio mixer.
I already searched on google but i can't find a way to do that...
someone has some hints for it???
NAudio uses tons of interop into Win32 functions that would be completely impossible to run in Silverlight.
UPDATE:
If you are looking for an MP3 player for Silverlight you may check out the Silverlight Audio Player.
I am working on one of the media project (windows application). In this the flv, avi and mpeg are the main file types which i have to play in application. I can use wmpLib, but it will not play flv files. So what procedure should i follow and what tools or libraries should i use.Is there any free opensource libraries to do media work. Thanks in advance
Also you can use ffmpeg lib see here, I think it would be easy to convert to another format using that for playback I don't really know, maybe you can take a look at the source of vlc or take a look at some flv opensourced player around.
If you have the right direct show filters installed media player will play flv files.