MediaPlayer OCX Code

GlennJames
GlennJames used Ask the Experts™
on
I am building an audio player for use in a semi-professional recording / broadcast environment. The player is based around the Windows MediaPlayer OCX. I want to be able to have 10 'cart' / audio players on screen at the same time (each with basic, play stop, and eject controls - as well as filename labels) and select the audio by means of a filelist box (the idea being that you can play / control up to 10 pieces of audio at once). My problem is that I can't work out the code / syntax to allow the programme to direct an audio file to MediaPlayer1 first and then by double clicking on another audio file in the filelist box to force the programme to load the second file to mediaPlayer2, and then MediaPlayer3, etc. I know that the code will be simple - but it is evading me at the moment. Please help. Thank you. Glenn.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
In your VB IDE select the menu <project>, then <references>. In the dialog box shown, you must select WindowsMediaPlayer (check it) and click OK. This will add a mediaplayer class to your project.


Option Explicit
Dim mpx As MediaPlayer.MediaPlayer 'insert this in the declaration section of your form'                                                                    
-------------------------------------------------------------

Private Sub playmusic(MySoundFilename)

Set mpx = New MediaPlayer.MediaPlayer

mpx.ShowAudioControls = True 'this if you want to show audio control panel'

mpx.Open MySoundFilename

End Sub

----------------------------------------------------------------

Private sub stopmusic()

mpx.Stop
mpx.filename = "" 'Unload file from MediaPlayer'
End Sub

--------------------------------------------------

Of course you can call the playmusic routine in the click event of a file list box, passing the filename selected in the MySoundFilename variable.

To stop music, add a command button that calls the stopmusic routine.
If you need several different media players you must declare different mpx objects : Dim mpx1 As MediaPlayer.MediaPlayer, mpx2 As MediaPlayer.MediaPlayer, mpx3........
You can also declare and use an array of objects if this can better fit your scope:
Dim mpx(10) As MediaPlayer.MediaPlayer

Hope this helps  
Marco
Author of the Year 2009

Commented:
Hi GlennJames,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept dmarco's comment(s) as an answer.

GlennJames, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept THIS comment as an answer.
==========
DanRollins -- EE database cleanup volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial