Solved

Media player

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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.
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…
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…

695 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