Solved

Play a mp3 file as bgsound in winform ?

Posted on 2004-05-01
9
657 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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