Solved

Play a mp3 file as bgsound in winform ?

Posted on 2004-05-01
9
637 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
Comment Utility
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
Comment Utility
   Public Const SND_NOSTOP As Integer = &H10 ' don't stop any currently playing sound



Dabas
0
 

Author Comment

by:tipt
Comment Utility
i can't understand. Please explain it clearly ?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 27

Expert Comment

by:Dabas
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
Those are VB6 declarations, the Long type should be Integer in VB.NET.

Bob
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

12 Experts available now in Live!

Get 1:1 Help Now