-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCLSMUSIC.CLS
More file actions
306 lines (246 loc) · 6.83 KB
/
Copy pathCLSMUSIC.CLS
File metadata and controls
306 lines (246 loc) · 6.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsMusic"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private m_objBasicAudio As IBasicAudio
Private m_objBasicVideo As IBasicVideo
Private m_objVideoWindow As IVideoWindow
Private m_objMediaControl As IMediaControl
Private m_objMediaPosition As IMediaPosition
Private m_hWnd As Long
Private m_FileName As String
Private m_HasAudio As Boolean
Private m_HasVideo As Boolean
' Constants
Private Const WS_VISIBLE = &H10000000
' Types
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
' Enums
Public Enum enumState
stStopped
stPlaying
stPaused
End Enum
' Functions
Public Property Get Width()
' Return the video width
On Error Resume Next
If HasVideo Then
Width = m_objBasicVideo.SourceWidth
Else
Width = 0
End If
End Property
Public Property Get Height()
' Return the video height
On Error Resume Next
If HasVideo Then
Height = m_objBasicVideo.SourceHeight
Else
Height = 0
End If
End Property
Public Property Let Window(ByVal hWnd As Long)
' Save the window
On Error Resume Next
m_hWnd = hWnd
End Property
Public Property Get Window() As Long
' Return the window
On Error Resume Next
Window = m_hWnd
End Property
Public Property Get FileName() As String
' Return the filename
On Error Resume Next
FileName = m_FileName
End Property
Public Property Let FileName(ByVal value As String)
' Set the filename
Dim r As RECT
Dim temp As Double
On Error Resume Next
' Save the filename
m_FileName = value
' Unload old objects
If Not (m_objMediaControl Is Nothing) Then
m_objMediaControl.Stop
Set m_objBasicAudio = Nothing
Set m_objBasicVideo = Nothing
Set m_objMediaControl = Nothing
Set m_objVideoWindow = Nothing
Set m_objMediaPosition = Nothing
End If
' Load new objects
Set m_objMediaControl = New FilgraphManager
m_objMediaControl.RenderFile FileName
Set m_objBasicAudio = m_objMediaControl
Set m_objBasicVideo = m_objMediaControl
Set m_objVideoWindow = m_objMediaControl
Set m_objMediaPosition = m_objMediaControl
' Check to see if there's audio
temp = m_objBasicAudio.Volume
If ERR.Number <> 0 Then
HasAudio = False
Else
HasAudio = True
End If
ERR.Clear
' Check to see if there's video
temp = m_objBasicVideo.SourceWidth
If ERR.Number <> 0 Then
HasVideo = False
Else
HasVideo = True
End If
ERR.Clear
' Hook the video to your window
If HasVideo Then
' Set the video size
GetWindowRect m_hWnd, r
With m_objVideoWindow
.WindowStyle = WS_VISIBLE
.Top = 0
.Left = 0
.Width = r.Right - r.Left
.Height = r.Bottom - r.Top
.Owner = m_hWnd
.Visible = 1
End With
' Show the first frame
Position = 0
End If
End Property
Public Sub Play()
' Play the file
On Error Resume Next
If Len(m_FileName) = 0 Then
Exit Sub
End If
If Position = Duration Then
Position = 0
End If
m_objMediaControl.Run
End Sub
Public Sub Pause()
'Pause playing
On Error Resume Next
m_objMediaControl.Pause
End Sub
Public Sub StopPlaying()
'Stop playing
On Error Resume Next
m_objMediaControl.Stop
End Sub
Public Property Let Position(ByVal NewPos As Double)
'Set the position
On Error Resume Next
With m_objMediaPosition
If NewPos < 0 Then
NewPos = 0
ElseIf NewPos > .Duration Then
NewPos = .Duration
End If
m_objMediaPosition.currentPosition = NewPos
If HasVideo Then
m_objMediaControl.Run
Do Until m_objMediaPosition.currentPosition > NewPos
Loop
m_objMediaPosition.currentPosition = NewPos
m_objMediaControl.Stop
End If
End With
End Property
Public Property Get Position() As Double
' Get the position
On Error Resume Next
Position = m_objMediaPosition.currentPosition
End Property
Public Property Get State() As enumState
' Return the state
On Error Resume Next
Dim TimeOut As Long
Dim s As Long
m_objMediaControl.GetState TimeOut, s
If s = 0 Then
State = stStopped
ElseIf s = 1 Then
State = stPaused
Else
State = stPlaying
End If
End Property
Public Property Get Speed() As Double
' Return the speed (normal speed is 1)
On Error Resume Next
Speed = m_objMediaPosition.rate
End Property
Public Property Let Speed(ByVal value As Double)
' Set the speed
On Error Resume Next
If value < 0.1 Then
value = 0.1
End If
m_objMediaPosition.rate = value
End Property
Public Property Get Duration() As Double
' Return how long the song is in milliseconds
On Error Resume Next
Duration = m_objMediaPosition.Duration
End Function
Public Property Get Volume() As Long
' Return the volume
On Error Resume Next
Volume = m_objBasicAudio.Volume
End Property
Public Property Let Volume(ByVal value As Long)
' Set the volume
On Error Resume Next
If value > 0 Then value = 0
If value < -10000 Then value = -10000
m_objBasicAudio.Volume = value
End Property
Public Property Get Balance() As Long
' Return the balance
On Error Resume Next
Balance = m_objBasicAudio.Balance
End Property
Public Property Let Balance(ByVal value As Long)
' Set the balance
On Error Resume Next
If value < -10000 Then value = -10000
If value > 10000 Then value = 10000
m_objBasicAudio.Balance = value
End Property
Public Property Get HasAudio() As Boolean
On Error Resume Next
HasAudio = m_HasAudio
End Property
Private Property Let HasAudio(ByVal value As Boolean)
On Error Resume Next
m_HasAudio = value
End Property
Public Property Get HasVideo() As Boolean
On Error Resume Next
HasVideo = m_HasVideo
End Property
Private Property Let HasVideo(ByVal value As Boolean)
On Error Resume Next
m_HasVideo = value
End Property