Solved

Play a mp3 file as bgsound in winform ?

Posted on 2004-05-01
9
659 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Write to a printer using vb.net 9 57
Help with error in Query 2 38
FInd Image Control Gridview 3 35
VB.Net - String Manipulation Scenario 2 29
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

713 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