This article uses native decoding of the naudio library instead of the WMP control and MCI, and occupies a small amount of resources. C # And. NET developers are recommended.
Naudio is an open-source audio processing class library for. Net platforms. It provides many simple methods to operate audio data.
Is an official exampleProgram.
Source codeAnd the sample program address see the official website: http://naudio.codeplex.com/
After analyzing the example program, we can obtain the minimum value for playing MP3.CodeAs follows:
1 Using System;
2 Using System. text;
3 Using Naudio. Wave;
4 Using Naudio. coreaudioapi;
5 Using System. Threading;
6 Using System. IO;
7
8 Namespace Kidplayer
9 {
10
11 Class Program
12 {
13 Static Void Main ()
14 {
15 Using (Var ms) = File. openread ( @ "Test . MP3 " ))
16 Using (VAR RDR = New Mp3filereader (MS ))
17 Using (VAR wavstream = Waveformatconversionstream. createpcmstream (RDR ))
18 Using (VAR bastream = New Blockalignreductionstream (wavstream ))
19 Using (VAR waveout = New Waveout (wavecallbackinfo. functioncallback ()))
20 {
21 Waveout. INIT (bastream );
22 Waveout. Play ();
23 While (Waveout. playbackstate = Playbackstate. Playing)
24 {
25 Thread. Sleep ( 100 );
26 }
27 }
28 }
29 }
30
31
32 }
33