Solved

Media player

Posted on 2004-03-26
3
312 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

863 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

24 Experts available now in Live!

Get 1:1 Help Now