Example of playing MP3 using C # And naudio decoding Libraries

Source: Internet
Author: User

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  

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.