Solved

Media player

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb6 programatically bring window to front 8 72
VB error "Type mismatch" 2 55
VBA Shell can't Find Word document 11 94
Visual Studio 2005 text editor 10 38
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

810 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