?
Solved

Media player

Posted on 2004-03-26
3
Medium Priority
?
349 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 60 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month9 days, 16 hours left to enroll

762 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