【VB开源代码栏目提醒】:以下是网学会员为您推荐的VB开源代码-Midi播放控制.frm,希望本篇文章对您学习有所帮助。
VERSION 5.00
Begin VB.Form Form1
Caption = "MIDI播放控制"
ClientHeight = 675
ClientLeft = 60
ClientTop = 345
ClientWidth = 3675
LinkTopic = "Form1"
ScaleHeight = 675
ScaleWidth = 3675
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton pause
Caption = "暂停"
Height = 375
Left = 2520
TabIndex = 2
Top = 120
Width = 975
End
Begin VB.CommandButton stop
Caption = "停止"
Height = 375
Left = 120
TabIndex = 1
Top = 120
Width = 975
End
Begin
VB.CommandButton play
Caption = "播放"
Height = 375
Left = 1320
TabIndex = 0
Top = 120
Width = 975
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim objDX As New DirectX7
Dim DMPerf As DirectMusicPerformance
Dim DMLoader As DirectMusicLoader
Dim DMSegment As DirectMusicSegment
Dim DMSegState As DirectMusicSegmentState
Dim startmidi As Long
Dim startmusic As Long
Dim pausetime As Long
Private Sub Form_Load()
Me.Show
Set DMLoader = objDX.DirectMusicLoaderCreate()
Set DMSegment = DMLoader.LoadSegment("sample1.mid")
DMSegment.SetStandardMidiFile
Set DMPerf = objDX.DirectMusicPerformanceCreate()
DMPerf.Init Nothing, 0
DMPerf.SetPort -1, 4
DMPerf.SetMasterVolume 500
DMPerf.SetMasterAutoDownload True
pausetime = 0
startmidi = 0
startmusic = 0
End Sub
Private Sub pause_Click()
startmusic = DMPerf.GetMusicTime
startmidi = DMSegState.GetStartTime
pausetime = pausetime + startmusic - startmidi
DMSegment.SetStartPoint (pausetime)
DMPerf.Stop DMSegment, DMSegState, 0, 0
End Sub
Private Sub play_Click()
Set DMSegState = DMPerf.PlaySegment(DMSegment, 0, 0)
End Sub
Private Sub stop_Click()
DMPerf.Stop DMSegment, DMSegState, 0, 0
DMSegment.SetStartPoint (0)
End Sub