Solved

Media player

Posted on 2004-03-26
3
299 Views
Last Modified: 2012-05-04
If I click on an button a muisc should be heard using a media player , real one or any thing else. I want the code for this.
0
Comment
Question by:rmvprasad
3 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 10689441
This will play a wav file:

' declarations
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

' usage
Private Sub Command1_Click()
sndPlaySound "c:\Somefile.wav", 1
End Sub
0
 
LVL 3

Accepted Solution

by:
Da_Weasel earned 20 total points
ID: 10690047
If you want the code for playing a music file with the default media player on someones computer then this is what you need:
The below code should start what ever program is associated with that file extention of the file passed to it.

' Paste the code below into the form of a Standard Exe project and replace the value assigned to the sMusicFile variable with your file>

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1
Dim sMusicFile as String

Private Sub Form_Load()
    sMusicFile = "D:\StreamRipper\Archive\Tracks\Drum and Bass\2 Cities\2 Cities - Concrete Vein.mp3"
    ShellExecute Me.hwnd, "open", sMusicFile, vbNullString, "C:\", SW_SHOWNORMAL
    Unload Me
End Sub

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

705 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

13 Experts available now in Live!

Get 1:1 Help Now