Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Public Declare Function mciGetDeviceID Lib "winmm.dll" Alias "mciGetDeviceIDA" (ByVal lpstrName As String) As Long
Public Declare Function waveOutGetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, lpdwVolume As Long) As Long
Public Declare Function GetWindowLong Lib "USER32" Alias "GetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function CallWindowProc Lib "USER32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal Hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowLong Lib "USER32" Alias "SetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Enum PlayTypeName
File = 1
CDAudio = 2
VCD = 3
RealPlay = 4
End Enum
Dim PlayType As PlayTypeName
Enum AudioSource
H = 0 ' "stereo"
L = 1 '"left"
R = 2 '"right"
End Enum
Enum Playstate
停止 = 1
暂停 = 2
播放 = 3
End Enum
Dim hWndMusic As Long
Dim prevWndproc As Long
'打开MCI设备,FILENAME为文件名,传值代表成功与否
Public Function OpenMusic(FileName As String, Optional Hwnd As Long) As Boolean
OpenMusic = False
Dim ShortPathName As String * 255
Dim RefShortName As String
Dim RefInt As Long
Dim MciCommand As String
Dim DriverID As String
CloseMusic '关闭 已经打开的歌曲 才可以打开新的歌曲
'获取短文件名
GetShortPathName FileName, ShortPathName, 255
RefShortName = Left(ShortPathName, InStr(1, ShortPathName, Chr(0)) - 1)
'MCI命令
DriverID = GetDriverID(RefShortName)
If DriverID = "RealPlayer" Then
PlayType = RealPlay
Exit Function
End If
MciCommand = "open " & RefShortName & " type " & DriverID & " alias NOWMUSIC"
'根据不同的格式加载不同的解码器
If DriverID = "AVIVideo" Or DriverID = "MPEGVideo" Or DriverID = "MPEGVideo2" Then
If Hwnd <> 0 Then
MciCommand = MciCommand + " parent " & Hwnd & " style child"
hWndMusic = GetWindowHandle
prevWndproc = GetWindowLong(hWndMusic, -4)
SetWindowLong hWndMusic, -4, AddressOf WndProc
Else
MciCommand = MciCommand + " style overlapped "
End If
End If
RefInt = mciSendString(MciCommand, vbNull, 0, 0)
mciSendString "set NOWMUSIC time format milliseconds", vbNullString, 0, 0
If RefInt = 0 Then
OpenMusic = True
LrcForm.LRC1.Sotp '关闭 已经打开的歌词
SongName = Trim$(Mid$(FileName, InStrRev(FileName, "\") + 1, Len(FileName))) & " " '滤除前面的路径
Naccuracy = 0 '还原歌词调整值 为 0
End If
End Function
Function WndProc(ByVal Hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = &H202 Then
MsgBox "OK"
End If
WndProc = CallWindowProc(prevWndproc, Hwnd, Msg, wParam, lParam)
End Function
'根据文件名,确定设备
Public Function GetDriverID(ff As String) As String
Select Case UCase(Right(ff, 3))
Case "MID", "RMI", "IDI"
GetDriverID = "Sequencer"
Case "WAV"
GetDriverID = "Waveaudio"
Case "ASX", "IVF", "LSF", "LSX", "P2V", "WAX", "WVX", ".WM", "WMX", "WMP"
GetDriverID = "MPEGVideo2"
Case ".RM", "RAM", ".RA", "MVB"
GetDriverID = "RealPlayer"
Case Else
GetDriverID = "MPEGVideo"
End Select
End Function
'播放文件
Public Function PlayMusic() As Boolean
Dim RefInt As Long
PlayMusic = False
RefInt = mciSendString("play NOWMUSIC", vbNull, 0, 0)
If RefInt = 0 Then
PlayMusic = True: DownloadLrc '加载 或下 载歌词
SetVolume ((Mian.Button1(6).Left - 660)) / 640 * 1000 '计算当前音量大小 '最大为1000
'检测播放速度 800 慢 1200 快
If menu.SpeedDown.Checked Then SetSpeed 800
If menu.SpeedUp.Checked Then SetSpeed 1200
'检测声道 默认 立体
If menu.AudioLeft.Checked Then SetAudioSource L '左声道
If menu.AudioRight.Checked Then SetAudioSource R
End If
End Function
'获取媒体的长度
Public Function GetMusicLength() As Long
Dim RefStr As String * 80
mciSendString "status NOWMUSIC length", RefStr, 80, 0
GetMusicLength = Val(RefStr)
End Function
'获取媒体的长度 00:00
Public Function GetMusicLengthString() As String
Dim RefStr As String * 80
mciSendString "status NOWMUSIC length", RefStr, 80, 0
GetMusicLengthString = CStr(Format(Int(Val(RefStr) \ 1000 \ 60), "00") & ":" & Format(Val(RefStr) \ 1000 Mod 60, "00.") & Val(RefStr) \ 100 Mod 10)
End Function
'设置当前播放进度条的长度 最长是 1980
Public Function HScrollWidth() As Long
Dim RefStr As String * 80
mciSendString "status NOWMUSIC position", RefStr, 80, 0
If Int(Val(RefStr)) <= 0 Then HScrollWidth = 1980: Exit Function
HScrollWidth = 1980 / GetMusicLength * Val(RefStr) ' * 1980
End Function
'设置当前播放进度条的长度和播放位置
Public Sub HScrollValue(Value As Single)
SetMusicPos ((1980 - (4240 - Value)) / 1980 * GetMusicLength) ' * Val(RefStr) ' * 1980
End Sub
'获取当前播放进度 毫秒
Public Function GetMusicPos() As Long
Dim RefStr As String * 80
mciSendString "status NOWMUSIC position", RefStr, 80, 0
GetMusicPos = Val(RefStr)
End Function
'获取当前播放进度 格式 00:00.0
Public Function GetMusicPosString() As String
Dim RefStr As String * 80
mciSendString "status NOWMUSIC position", RefStr, 80, 0
GetMusicPosString = CStr(Format(Int(Val(RefStr) \ 1000 \ 60), "00") & ":" & Format(Val(RefStr) \ 1000 Mod 60, "00.") & Val(RefStr) \ 100 Mod 10)
End Function
'获取媒体的当前进度
Public Function SetMusicPos(Position As Long) As Boolean
Dim RefInt As Long
SetMusicPos = False
RefInt = mciSendString("seek NOWMUSIC to " & Position, vbNull, 0, 0)
If RefInt = 0 Then PlayMusic: SetMusicPos = True
End Function
'暂停播放
Public Function PauseMusic() As Boolean
Dim RefInt As Long
PauseMusic = False
RefInt = mciSendString("pause NOWMUSIC", vbNull, 0, 0)
If RefInt = 0 Then PauseMusic = True
End Function
'关闭媒体
Public Function CloseMusic() As Boolean
Dim RefInt As Long
CloseMusic = False
RefInt = mciSendString("close NOWMUSIC", vbNull, 0, 0)
If RefInt = 0 Then CloseMusic = True
End Function
'全屏播放
Public Function PlayFullScreen() As Boolean
Dim RefInt As Long
PlayFullScreen = False
RefInt = mciSendString("play NOWMUSIC fullscreen", vbNull, 0, 0)
If RefInt = 0 Then PlayFullScreen = True
End Function
'设置声音大小
Public Function SetVolume(Volume As Long) As Boolean
Dim RefInt As Long
SetVolume = False
RefInt = mciSendString("setaudio NOWMUSIC volume to " & Volume, vbNull, 0, 0)
If RefInt = 0 Then SetVolume = True
End Function
'设置声道
'======================================================
Public Function SetAudioSource(sAudioSource As AudioSource) As Boolean
Dim RefInt As Long
Dim strSource As String
Select Case sAudioSource
Case 1: strSource = "left"
Case 2: strSource = "right"
Case 0: strSource = "stereo"
End Select
SetAudioSource = False
RefInt = mciSendString("setaudio NOWMUSIC source to " & strSource, vbNull, 0, 0)
If RefInt = 0 Then SetAudioSource = True
End Function
'设置播放速度
Public Function SetSpeed(Speed As Long) As Boolean
Dim RefInt As Long
SetSpeed = False
RefInt = mciSendString("set NOWMUSIC speed " & Speed, vbNull, 0, 0)
If RefInt = 0 Then SetSpeed = True
End Function
'静音True为静音,FALSE为取消静音
Public Function SetAudioOnOff(AudioOff As Boolean) As Boolean
Dim RefInt As Long
Dim OnOff As String
SetAudioOff = False
If AudioOff Then OnOff = "off" Else OnOff = "on"
RefInt = mciSendString("setaudio NOWMUSIC " & OnOff, vbNull, 0, 0)
If RefInt = 0 Then SetAudioOff = True
End Function
'获得当前媒体的状态是不是在播放
Public Function IsPlaying() As Playstate
Dim sl As String * 255
mciSendString "status NOWMUSIC mode", sl, Len(sl), 0
'MsgBox sl
If Left(sl, 7) = "playing" Or Left(sl, 2) = "播放" Then
IsPlaying = 播放
ElseIf Left(sl, 7) = "stopped" Or Left(sl, 2) = "停止" Then
IsPlaying = 停止
Else
IsPlaying = 暂停
End If
End Function
'获得播放窗口的handle
Public Function GetWindowHandle() As Long
Dim RefStr As String * 160
mciSendString "status NOWMUSIC window handle", RefStr, 80, 0
GetWindowHandle = Val(RefStr)
End Function
'获取DeviceID
Public Function GetDeviceID() As Long
GetDeviceID = mciGetDeviceID("NOWMUSIC")
End Function
相关推荐
4. **音频播放技术**:VB内置的MediaPlayer控件可以播放多种音频格式,但可能不支持所有流媒体服务。开发者可能采用了第三方库,如NAudio,来增强播放功能,支持更多格式并实现在线播放。 5. **数据解析**:获取到...
为了处理不同格式的音乐文件,播放器可能内置了多种音频编解码器,例如MP3、AAC、FLAC等。 对于DJ音乐特有的特性,播放器可能包含了一些专业功能。例如,它可能有同步播放功能,使两首歌曲能无缝过渡;节奏分析和...
TimeEdit100是一款支持多种音频格式的播放器控件,包括WAV,它不仅提供播放控制,还能显示音频的实时波形。 `TimeEdit100.ctl`和`TimeEdit100.ctx`是TimeEdit100控件的相关文件,其中`.ctl`是控件的接口定义文件,`...
VB提供了多种控件,如按钮、列表框、文本框等,用于创建交互式的用户界面。在这个点歌系统中,用户可能通过列表或搜索功能选择歌曲,然后点击播放按钮开始演唱。界面设计应该简洁易用,以便用户快速找到他们想要的...
7. **音频格式支持**: `PlaySound` 函数支持WAV、MIDI等多种音频格式,但不支持MP3等更常见格式。如果要播放MP3,可能需要引入其他库,如DirectX或第三方的MP3解码组件。 8. **错误处理**: 在编程中,错误处理是必...
综上所述,VB编写的模拟电子钢琴项目结合了事件驱动编程、音频处理、用户界面设计、音乐理论应用、源代码管理、MIDI技术以及模块化编程等多个方面的知识。通过深入学习这些内容,开发者可以创建出更加复杂且功能丰富...
可能包括支持多种音色、节奏模式,增加编辑和保存简谱的功能,以及与其他音乐格式(如MIDI)的互换性等。 由于压缩包中仅有一个名为“简谱播放程序”的文件,可以推测这是整个工程的主文件,可能包含了VB代码、资源...
- **MIDI支持**:MIDI(乐器数字接口)是音乐制作中常用的标准,VB音效合成播放器可能能读取和播放MIDI文件。 - **效果器插件**:软件可能支持VST(Virtual Studio Technology)插件,允许用户添加各种音效处理模块...
2. **核心WMP(Windows Media Player)组件**:该播放器可能使用了Windows Media Player的ActiveX控件,这是一个集成在Windows系统中的多媒体播放引擎,能够播放多种音频和视频格式。通过调用WMP的API函数,VB6.0...
'3、使用WindowsMediaPlayer控件,进行音乐文件的播放操作。 '4、拖拽文件到窗体操作进行添加音乐文件播放列表,可修改成图片拖拽或其它文件拖拽。 '5、用模块实现INI文件的读写操作,同步实现了软件版本号的读,写...
4. **多媒体播放**:VB6.0中的MCI(Multimedia Control Interface)控件或Windows Media Player ActiveX控件可以用于音乐播放。MCI控件可以直接控制音频文件的播放,而Windows Media Player控件则提供更丰富的功能,...
2. **票种管理**:系统应能定义和管理多种票种,如电影票、音乐会门票、体育赛事票等,每种票可能有不同的价格、折扣策略和可用性。 3. **库存管理**:实时跟踪票务库存,自动更新售出和剩余票数,防止超售。同时,...
综上所述,VB音乐播放器是一个集成了多媒体处理、网络通信、文件操作、图形用户界面和模块化编程等多种技术的综合性应用。通过巧妙地结合这些技术,开发者为用户创造了一个既实用又有趣的音乐播放环境。
5. **多音频格式支持**:VB可以处理多种音频格式,如MP3、WAV、WMA等,只需确保选择的播放组件支持相应的格式。 6. **自定义音频效果**:通过API调用或第三方库,VB还可以实现更复杂的音频处理,如均衡器效果、淡入...
4. **灵活的播放列表管理**:用户可自定义播放列表,并支持顺序播放、随机播放等多种播放模式。 5. **完善的数据库设计**:系统采用SQL数据库存储歌曲信息、用户信息等数据,保证了数据的稳定性和安全性。 **二次...
Windows Media Player是微软提供的多媒体播放解决方案,支持多种音频和视频格式,具有广泛的兼容性和稳定性。 该播放器采用了类似于WINAMP的皮肤界面,这表明它可能允许用户自定义界面外观,以提高用户体验和个性化...
- **多媒体播放器**:利用 DirectX 或其他第三方组件,实现音乐播放、视频播放等多媒体功能。 #### 七、学习资源推荐 - **官方文档**:访问微软官方网站获取最新的 VB 6.0 文档和技术支持。 - **在线课程**:...
在压缩包中的"儿童益智游戏"文件中,可能包含了VB工程文件(.vbp)、窗体文件(.frm)、模块文件(.bas)以及其他资源文件(如图片、音频)。通过这些文件,我们可以看到游戏的完整结构和实现细节,包括控件布局、...
首先,关于**背景音乐**的实现,VB提供了多媒体控制模块,可以集成到应用程序中,允许用户在记录日记时播放音乐。这通常通过`MMControl`控件或者`MSACM32.DLL`库来实现。开发者需要设置音乐文件的路径,然后通过控件...
- **声音效果**:VB中可以通过控件播放音频文件,实现游戏音效的添加,如背景音乐、移动或完成关卡时的提示音。 - **清晰画面**:利用VB的图形绘制功能,可以设计出各种游戏元素,如箱子、玩家角色、墙壁等,并...