Here is a simple example in VB. You need to add a reference to MediaCenter.tlb to your VB project. In Java you do it in a corresponding way but you need a tool that will generate COM interfaces for MC based on MediaCenter.tlb. There is a number of such tools both commertial and free (open source). I’m using Jawin from http://sourceforge.net/projects/jawinproject/
Public Class Form1
Inherits System.Windows.Forms.Form
Dim mcAutomation As MediaCenter.IMJAutomation
Dim mcFilesAutomation As MediaCenter.IMJFilesAutomation
Dim mcPlaybackAutomation As MediaCenter.IMJPlaybackAutomation
Dim mcCurPlaylistAutomation As MediaCenter.IMJCurPlaylistAutomation
Dim start As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' First try to get automation interface to an already running Media Center
On Error Resume Next
mcAutomation = GetObject(, "MediaJukebox Application")
If Err.Number = 429 Then
' If MC is not runing then start it and get interface
mcAutomation = CreateObject("MediaJukebox Application")
End If
' Get interfaces to playback and to playing now list
mcPlaybackAutomation = mcAutomation.GetPlayback()
mcCurPlaylistAutomation = mcAutomation.GetCurPlaylist()
' Get all files in MC library
mcFilesAutomation = mcAutomation.Search("")
' Add all these files to playing now
Dim file As MediaCenter.IMJFileAutomation
Dim i As Integer
Dim key As Integer
For i = 1 To mcFilesAutomation.GetNumberFiles()
file = mcFilesAutomation.GetFile(i)
key = file.GetKey()
mcCurPlaylistAutomation.AddFileByKey(key, i)
Next
start = True
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
' If not playing right now
If mcPlaybackAutomation.State <> MediaCenter.MJPlaybackStates.PLAYSTATE_PLAYING Then
' Play
If start Then
' Start playing playing now list
mcFilesAutomation.Play(0)
start = False
Else
' Toggle pause state = play whatever was playing
mcPlaybackAutomation.Pause()
End If
Button1.Text = "Pause"
Else
' Toggle pause state = pause
mcPlaybackAutomation.Pause()
Button1.Text = "Play"
End If
End Sub
End Class