Solved

Play a mp3 file as bgsound in winform ?

Posted on 2004-05-01
9
660 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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