This repository has been archived by the owner on Jul 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModMusic2.vb
48 lines (43 loc) · 2.21 KB
/
ModMusic2.vb
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
Imports System.Threading
Public Module ModMusic2
Private MusicPlayer2 As MediaPlayer
Private MusicThread As Thread
Private IsInited As Boolean = False
Public Sub MusicStartRun2()
If IsInited Then Exit Sub
IsInited = True
'初始化
MusicThread = New Thread(Sub()
'初始化 MediaPlayer
MusicPlayer2 = New MediaPlayer
MusicPlayer2.Volume = 0
Do While True
Thread.Sleep(15)
'调整音乐
If MusicName <> MusicNamePlaying Then
Dim RawPosition = MusicPlayer2.Position
MusicPlayer2.Open(New Uri(Path & "\Sounds\" & MusicName))
MusicPlayer2.Play()
MusicNamePlaying = MusicName
If MusicInheritProgress Then MusicPlayer2.Position = RawPosition
End If
'渐变音量
MusicPlayer2.Volume = MusicPlayer2.Volume * 0.997 + MusicVolume * 1.5 * 0.003
'循环播放
If MusicPlayer2.Position + New TimeSpan(0, 0, 0, 0, 20) >= MusicPlayer2.NaturalDuration Then
MusicPlayer2.Position = New TimeSpan(0, 0, 0, 0)
End If
Loop
End Sub)
MusicThread.Start()
End Sub
Private MusicVolume As Double = 0
Private MusicName As String = "Boss 2.mp3"
Private MusicInheritProgress As Boolean = False
Private MusicNamePlaying As String = ""
Public Sub MusicChange2(Name As String, Volume As Double, InheritProgress As Boolean)
MusicName = Name
MusicVolume = Volume
MusicInheritProgress = InheritProgress
End Sub
End Module