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
/
ModMusic.vb
48 lines (43 loc) · 2.19 KB
/
ModMusic.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 ModMusic
Private MusicPlayer As MediaPlayer
Private MusicThread As Thread
Private IsInited As Boolean = False
Public Sub MusicStartRun()
If IsInited Then Exit Sub
IsInited = True
'初始化
MusicThread = New Thread(Sub()
'初始化 MediaPlayer
MusicPlayer = New MediaPlayer
MusicPlayer.Volume = 0
Do While True
Thread.Sleep(15)
'调整音乐
If MusicName <> MusicNamePlaying Then
Dim RawPosition = MusicPlayer.Position
MusicPlayer.Open(New Uri(Path & "\Sounds\" & MusicName))
MusicPlayer.Play()
MusicNamePlaying = MusicName
If MusicInheritProgress Then MusicPlayer.Position = RawPosition
End If
'渐变音量
MusicPlayer.Volume = MusicPlayer.Volume * 0.997 + MusicVolume * 0.003
'循环播放
If MusicPlayer.Position + New TimeSpan(0, 0, 0, 0, 20) >= MusicPlayer.NaturalDuration Then
MusicPlayer.Position = New TimeSpan(0, 0, 0, 0)
End If
Loop
End Sub)
MusicThread.Start()
End Sub
Private MusicVolume As Double = 0.02
Private MusicName As String = "Boss 1.mp3"
Private MusicInheritProgress As Boolean = False
Private MusicNamePlaying As String = ""
Public Sub MusicChange(Name As String, Volume As Double, InheritProgress As Boolean)
MusicName = Name
MusicVolume = Volume
MusicInheritProgress = InheritProgress
End Sub
End Module