How to play audio files

Source: Internet
Author: User

I believe many of my friends want to use C # to play games and other games. Of course, it is inevitable to play some audio files or video files. If DirectX is installed on your computer, this folder is usually found in c: \ windows \ Microsoft. NET.

This is the use of DirectX programming must use a few DLL files, it is very important! If you want to know what it contains
You can create a new windowsform project, include these DLL files, and view them using the Object Browser in. Net to know which functions are included.

After the player is included, we can start to develop our player.
Add a button button1, double-click it, and then addCode

Code
Using System;
Using System. Collections. Generic;
Using System. componentmodel;
Using System. Data;
Using System. drawing;
Using System. LINQ;
Using System. text;
Using System. Windows. forms;
Using Microsoft. DirectX. audiovideoplayback;

Namespace Windowsformsapplication1
{
Public   Partial   Class Form2: Form
{

Audio audio =   Null ;

Public Form2 ()
{
Initializecomponent ();
}

Private   Void Button#click ( Object Sender, eventargs E)
{
Openfiledialog dialog1 = New Openfiledialog ();
Dialog1.title =   " Browse to find sound file to play " ;
Dialog1.initialdirectory =   @" C :\ " ;
Dialog1.filter =   " WAV Files (*. wav) | *. wav " ;
Dialog1.filterindex =   2 ;
Dialog1.restoredirectory =   True ;

Audio =   New Audio (dialog1.filename, True );
}
}
}

You can call methods such as audio. Stop () and audio. Pause. You can see a lot of methods you need using the Object Browser.
If you study it carefully, you can make a satisfactory player! Success!

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.