VERSION 5.00
Begin VB.Form frmiTunes 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "iTunes"
   ClientHeight    =   1125
   ClientLeft      =   45
   ClientTop       =   420
   ClientWidth     =   1335
   ClipControls    =   0   'False
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   1125
   ScaleWidth      =   1335
   StartUpPosition =   3  'Windows Default
End
Attribute VB_Name = "frmiTunes"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private WithEvents iTunesObj As iTunesApp
Attribute iTunesObj.VB_VarHelpID = -1
Private Accessible As Boolean
Public Opened As Boolean

Private Sub Form_Load()
    On Error GoTo hErr:
    Opened = True
    Accessible = False
    Set iTunesObj = New iTunesApp
    Accessible = Not (Media.Opened)
    Exit Sub
hErr:
    ErrorHandler "iTunes Handler", "Load"
End Sub
'
'Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'    On Error GoTo hErr:
'    Opened = False
'    Set iTunesObj = Nothing
'    Accessible = False
'    Exit Sub
'hErr:
'    ErrorHandler "iTunes Handler", "QueryUnload"
'End Sub

Private Sub iTunesObj_OnAboutToPromptUserToQuitEvent()
    On Error GoTo hErr:
    Set iTunesObj = Nothing
    Accessible = False
    Exit Sub
hErr:
    ErrorHandler "iTunes Handler", "PromptToQuit"
End Sub

Private Sub iTunesObj_OnCOMCallsDisabledEvent(ByVal Reason As iTunesLib.ITCOMDisabledReason)
    On Error GoTo hErr:
    Accessible = False
    Set iTunesObj = Nothing
    Exit Sub
hErr:
    ErrorHandler "iTunes Handler", "CallsDisabled"
End Sub

Private Sub iTunesObj_OnCOMCallsEnabledEvent()
    On Error GoTo hErr:
    Accessible = True
    Set iTunesObj = New iTunesApp
    Exit Sub
hErr:
    ErrorHandler "iTunes Handler", "CallsEnabled"
End Sub

Private Sub iTunesObj_OnPlayerPlayEvent(ByVal iTrack As Variant)
    'On Error GoTo hErr:
    Accessible = True
hErr:
    ErrorHandler "iTunes Handler", "PlayerPlay"
End Sub

Private Sub iTunesObj_OnPlayerPlayingTrackChangedEvent(ByVal iTrack As Variant)
    On Error GoTo hErr:
    Accessible = True
hErr:
    ErrorHandler "iTunes Handler", "PlayerPlayingTrackChanged"
End Sub

Private Sub iTunesObj_OnPlayerStopEvent(ByVal iTrack As Variant)
    On Error GoTo hErr:
    Accessible = True
hErr:
    ErrorHandler "iTunes Handler", "PlayerStop"
End Sub

Private Sub iTunesObj_OnQuittingEvent()
    On Error GoTo hErr:
    Accessible = False
    Set iTunesObj = Nothing
    Exit Sub
hErr:
    ErrorHandler "iTunes Handler", "Quitting"
End Sub

Private Sub iTunesObj_OnUserInterfaceEnabledEvent()
    On Error GoTo hErr:
    Accessible = True
    Exit Sub
hErr:
    ErrorHandler "iTunes Handler", "UIEnabled"
End Sub

Public Function CurrentTrack() As String
    If Accessible = True Then
        CurrentTrack = iTunesObj.CurrentTrack.Artist & " - " & iTunesObj.CurrentTrack.Name
    Else
        CurrentTrack = "iTunes is busy!"
    End If
    Exit Function
hErr:
    ErrorHandler "iTunes Handler", "CurrentTrack"
End Function
