.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> WPF >> Post New Resource Bookmark and Share   

 Subscribe to Articles

A Simple MP3 Player in WPF using VB.NET

Posted By:Hefin Dsouza       Posted Date: August 11, 2009    Points: 25    Category: WPF    URL: http://www.dotnetspark.com  
 

Simple MP3 Player

Introduction : This is a simple Music Player that can play single Mp3 Songs at a time. It is a very basic player with Fast Forward, Rewind , Stop and Play Functions. The Player also displays Mp3 Information like Total Duration of the Song , Remaining Time , Elapsed Time and Status.  
Technical Information : The Project makes use of a number of External Dll's for functionality.

1)Microsoft.DirectX.AudioVideoPlayback.dll

 2)Microsoft.DirectX.Direct3D.dll

3)Microsoft.DirectX.DirectPlay.dll

4)Microsoft.DirectX.DirectSound.dll

5)Microsoft.DirectX.dll

 

Understanding The Code : Below I have demonstrated some steps that will allow you to build your own MP3 Player in .Net.

(Please Note The Below Code is In Visual Basic. Net)

 

Initial Steps :

1)You need to Add Reference to The Above Mentioned Dll's (You will find it in the Attachment)
2)Import the following Namespaces


Imports Microsoft.DirectX

Imports Microsoft.DirectX.AudioVideoPlayback

Imports Microsoft.DirectX.Direct3D

Imports Microsoft.DirectX.DirectPlay

Imports Microsoft.DirectX.DirectSound
3)Create an Object of Audio Class

Dim song As Audio

4)To Load the Mp3 In the Audio object and to Play

5)To Stop a Playing Song

Private Sub stopBtn_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles stopBtn.Click

    Try

song.Stop()

Catch ex As Exception

End Try

End Sub

 

6) For Fast Forward and Rewind


Private Sub forwBtn_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles forwBtn.Click

        Try
song.CurrentPosition += 2

Catch ex As Exception

Try 

song.CurrentPosition = song.Duration 

                    Catch ex1 As Exception

End Try

End Try

End Sub

'For Rewind

Private Sub rewindBtn_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles rewindBtn.Click

            Try

song.CurrentPosition -= 2

Catch ex As Exception

Try 

song.CurrentPosition = 0

Catch ex1 As Exception

End Try

End Try

End Sub

 

These were some of the Important code's to create your own MP3 Player.
I have Attached the working Copy of the Whole Project along with the source code.
Important Note : To Run the Sample You need to Have
a) Visual Studio 2008 Service Pack 1
b) .Net Framework 3.5 + Service Pack 1
c) DirectX Compatible Sound Card
d) Speakers
e) Few Mp3 Songs to Test

Private Sub playBtn_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles playBtn.Click

openfile.Filter = "Audio Files(*.wav,*.mp3,*.cda)|*.wav;*.mp3;*.cda"

If openfile.ShowDialog() = Forms.DialogResult.OK Then

TextBox1.Text = openfile.FileName 

song = New Audio(TextBox1.Text)

songTrack.Maximum = song.Duration 

song.Play()
tm.Interval = 60

tm.Start()

StLabel.Content = "Status : Playing"
End If
End Sub

Regards
Hefin Dsouza

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend