Solved

Play a mp3 file as bgsound in winform ?

Posted on 2004-05-01
9
650 Views
Last Modified: 2007-12-19
User can select a mp3 file they want (i used OpenFileDialog to open it). and this file will be a bgsound of this winform. How can i do it ?


It's urgent. TIA
0
Comment
Question by:tipt
9 Comments
 
LVL 27

Accepted Solution

by:
Dabas earned 250 total points
ID: 10969610
Hi tipt:
 Private Declare Function PlaySoundAPI Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

    Public Sub PlaySound(ByVal Path As String)
        If PlaySoundAPI(Path, 0, SND_NOSTOP) = 0 Then
            Beep()
        End If
    End Sub

Dabas
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10969611
   Public Const SND_NOSTOP As Integer = &H10 ' don't stop any currently playing sound



Dabas
0
 

Author Comment

by:tipt
ID: 10970459
i can't understand. Please explain it clearly ?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 27

Expert Comment

by:Dabas
ID: 10971026
tipt:
Add the above code to your program,

then once you have found the path to the file to play using opendialog,
Call the PlaySound Sub, passing the file name as its parameter

Dabas
0
 

Expert Comment

by:jxharding
ID: 10993407

Good day Dabas
i took a form and put a button on it, and then pasted this

code into it.
i just get 2 beeps.
when i console.writeline(path) in the playsound sub, the

path shows correctly.
there are no other files playing at the time.
this is prob the nearest i got to playing a mp3 though

    Private Declare Function PlaySoundAPI Lib "winmm.dll"

Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule

As Long, ByVal dwFlags As Long) As Long

    Public Const SND_NOSTOP As Integer = &H10 ' don't stop

any currently playing sound
    Public Sub PlaySound(ByVal Path As String)
        If PlaySoundAPI(Path, 0, SND_NOSTOP) = 0 Then
            Beep()
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object,

ByVal e As System.EventArgs) Handles Button1.Click
        Dim playstring As String = "C:\1.mp3"
        PlaySoundAPI(playstring, 0, SND_NOSTOP)
        PlaySound(playstring)
    End Sub
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10993626
jxharding,

You are right. PLAYSoundAPI seems to be geared to wav files, not mp3 ones.
This PAQ might point to the right direction:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20929854.html#10675256 "Background music in vb .net"

Dabas
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 250 total points
ID: 11177058
Those are VB6 declarations, the Long type should be Integer in VB.NET.

Bob
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now