Previous..
Next...
Here i will explain How to play a audio file in window application.
Step(1): Form
Drag and down 2 button and a textBox for showing audio path
Step(2): Code
Double click on button and write this code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Text;
using System.IO;
using System.IO;
namespace First_Csharp_app
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Choose_Btn_click(object sender, EventArgs e)
{
OpenFileDialog openfile = new OpenFileDialog ();
if(openfile .ShowDialog() ==System.Window.Forms.DialogResult.OK)
{
{
OpenFileDialog openfile = new OpenFileDialog ();
if(openfile .ShowDialog() ==System.Window.Forms.DialogResult.OK)
{
TextBox1.Text = openfile .FileName;
}
private void Audioplayer_click(object sender, EventArgs e)
{
{
try
{
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = textBox1.text;
player.Load();
player.PlaySync();
}
catch (Exception ex)
MessageBox.Show(ex.Message);
}
}
Run your application and select audio file and then play your audio player.
Previous..
Next...