Recently bored, want to listen to the song. Poor new computer songs on the two or three, to listen to the other will have to play on the old computer. However, the antique but sturdy book by the wife mercilessly occupied. Helpless.
Reasoning, get it, write a program to play it. Do a C/s player.
The ideal is beautiful, the reality is cruel. After tedious searching and testing, Nadio (Oct naudio 1.6), the open-source third-party plugin, was found.
Write a conclusion and write the process first.
Conclusion
one , the use of. NET SoundPlayer to play wave files need to pay attention to several places:
- When using FileStream or MemoryStream, the position of the stream must be 0 and the stream cannot be closed . That is, you need to be aware of the flow object's life cycle .
- You cannot use a section of the wave file to play.
- Stream property to specify the flow to play
Second, There are several places to play files using the Naiduo library
- To judge the file type, first Judge wave file, if not wave file, then use Mp3freame to determine whether the mp3 file
- If you use the Naudio library to provide waveout playback, it is important to note that it does not put playbackstate to playbackstate.stoppedwhen the file is finished, this needs to be judged manually.
- To get/set the progress , time , and volume of the playback, you need to use WaveChannel32
- The Volume of the Naudio library has a problem with the volume call, using the default values.
Process
a ,Naudio provides examples of
- Some examples are provided in the source files for Naudio
- http://naudio.codeplex.com/'s Web page,Projects Using Naudio also has some
- Of course, the better is the documention below how does I ...? there are direct waves and MP3 code to play
- and a simple C # Player MP3 with Naudio article
two , start
Everyone knows the basic composition of the player includes: volume control , progress Control , time display , play , pause , stop Wait for a few basic moves, and the event that is raised at the end of the playback. So
Audioplayer is the object of the player, but the actual playback operation is done by Naudio. So
Use Audiocore to complete the Naudio actual play action. So, how do you manipulate volume, progress, and display time? This is to Audiovolume audiotimeposition to finish.
OK, all the objects have been established, only need to combine organically to work. Let's do a real test here.
Let's listen to the "Journey to the Shan Tianfang"
Third, the end
The end seems a little faster. Hi~hi~, this is efficiency. Attached code. Interested students can use Reflector anti-compilation Goldli. Utility.AudioPlayer.dll . There is a problem sending an email. It's flashing.
====================================================
Play mp3 example with C # and Naudio decoding libraries
Instead of using WMP controls and MCI, this article uses the Naudio library to natively decode and occupy small resources. Recommended for use by C # and. NET developers.
Naudio is an open source for. The Audio processing class library under the net platform. Provides a number of easy ways to manipulate audio data.
is the official sample program.
Source Code and sample program address at official website: http://naudio.codeplex.com/
After analyzing the sample program, we can conclude that the minimum code for playing MP3 is as follows:
Using System; Using System.Text; Using Naudio.wave; Using Naudio.coreaudioapi; Using System.Threading; Using System.IO; Namespace kidplayer{ class program { static void Main () { using (var ms = File.openread (@ "Test.mp3 ")) using (var rdr = new Mp3filereader (ms)) using (var wavstream = Waveformatconversionstream.createpcmstream ( RDR), using (var bastream = new Blockalignreductionstream (wavstream)) using (var waveout = new Waveout ( Wavecallbackinfo.functioncallback ())) { waveout.init (bastream); Waveout.play (); while (waveout.playbackstate = = playbackstate.playing) { thread.sleep (+) ; } }}}
==============================================
Go: Play mp3 example with C # and Naudio decoding library
http://naudio.codeplex.com/
[HTML]View Plaincopyprint?
- Using Naudio;
- Using Naudio.wave;
- Using Naudio.coreaudioapi;
- Waveout waveout = null;
- var rdr = new Mp3filereader ("1.mp3");
- var wavstream = waveformatconversionstream.createpcmstream (RDR);
- var bastream = new Blockalignreductionstream (Wavstream);
- Waveout = New Waveout (Wavecallbackinfo.functioncallback ());
- Waveout.init (Bastream);
- Waveout.play ();
Using naudio;using naudio.wave;using Naudio.coreaudioapi; Waveout waveout = Null;var rdr = new Mp3filereader ("1.mp3"); var wavstream = Waveformatconversionstream.createpcmstream ( RDR) var bastream = new Blockalignreductionstream (wavstream); waveout = new Waveout (Wavecallbackinfo.functioncallback ( ); Waveout.init (Bastream); Waveout.play ();
Currently testing MP3 files that support 320kbps bitrate
============================================
Use Naudio 2012-01-08 22:09:10 in Unity
Category: Embedded
When I use the Unity3d engine I would like to be able to join the recording function, but the official version of Naudio DLL library will fail when loading Unity3d.
After my practice, I found the problem was that the official Naudio library was compiled with the csc.exe and. NET Framework 4.0来, but Unity3d only supported mono and. NET Framework 2.0, and when some syntax differences were modified, I succeeded in compiling and was successful in the recording and playback tests.
I set up a Google Code project:
http://code.google.com/p/naudio-with-unity3d/
To make it easier for others to use DLLs without having to spend a lot of effort to modify the syntax differences.
C # wave MP3 Player Quest