It is necessary to use the VB to make a multimedia program.

zhaozj2021-02-08  206

There have been many friends on CSDN, such as "How to Play AVI, Wave, Midi File",: "Who knows how to play AVI and MPG with API? To set the image to the set form" "How to play two WAV files at the same time, in fact, using a class module to do everything, do not need any control, what is the following module (I don't know where to find it, it is 9CBS), I study After removing it, it is better to save the following module as mmedia.cls' -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------- Option Explicit

'-------------- Truezq Latest Update 2001-01-12 -------------------' File Name: MMEDIA. CLS 'Note:: A multimedia class, play AVI, Wave, MIDI file' usage: 'Dim MultiMedia as new mmedia'multimedia.mmopen "c: /test.wav" MultiMedia.mmplay'! Remember: At the end of the program, you must use SET MULTIMEDIA = Nothing to release the resource! ! ! '------------------------------------- ----

'- = - = - = - attribute - = - = - = -' sfilename Current File Name 'Nensity File Length (read-only)' NPosition Current Position 'Sstatus Current Status (Reading)' BWAIT TRUE / FALSE. Decide whether Waiting for play

'- = - = - = - = - = - = - = -' mmopen Open the file you want to play 'MMClose Close the current file' MMPAUSE Pause 'mmstop Stop Stop Stop Stop Stop Start Playback' MMSeek < Position> seeks to a position in the file 'mmplay play

'------------------------------------- -------------

The current state of the Private sAlias ​​As String 'alias' Private hWnd As LongPrivate sFilename As String' current file name Private nLength As Single 'file length Private nPosition As Single' current location Private sStatus As String 'Private bWait As Boolean' decision whether to wait for playing End Const ws_child = & h40000000 '------------ API declaration ------------- Private Declare Function McISendstring lib "Winmm.dll" _ alias "mciSendstringa" (byval lpstringa " As string, _ byval lpstrreturnstring as string, byval ureturnLENGTH AS long, _ byval hwndcallback as long) AS Long'private Declare Function GetActiveWindow LIB "User32" () AS INTEGER

'When Sthefile is an AVI file, the parameter hWnd specifies where to play where' if hWnd = 0, then open a window to play animation. 'If you can't hear MIDI music, please test it with a media player under Windows. 'File Name Can't bring space public Sub mmopen (Byval Sthefile As String, OPTIONAL HWND As long = 0)

DIM NRETURN AS Long Dim Stype As String 'File Type Static Nnum As Integer If Salias <> "" THEN' Close Start Opening File MMClose End if if (Dir (Sthefile) = ") The 'determines if it is an existing file SFileName = "File" & Sthefile & "Does not exist!" EXIT SUB ELSE SFILENAME = Sthefile 'nnum = nnum 1 end if' stop salias = sfilename 'with file names, avoid alias conflicts! 'Judgment file type SELECT CASE $ (Right $ (Sthefile, 3)) Case "WAV" stype = "Waveaudio" Case "AVI" stype = "Avivideo" Case "MID" style = "sequencer" case else' unknown file format ,drop out. EXIT SUB End Select if stype = "avivideo" and hwnd> 0 THEN NRETURN = McISendstring ("Open" & Sthefile & "Alias" & Salias _ & "Type Avivideo Parent" & HWnd & "STYLE" & LTRIM $ (STR) Ws_child), 0 &, 0, 0) Else Nreturn = McISendstring ("Open" & Sthefile & "Alias" & Salias _ & "Type" & stype, "", 0, 0) end if End sub 'close the currently open Multimedia file pub mmclose () DIM NRETURN AS long 'If there is no file open, exit if Salias = "" "" "" & salias, "", 0, 0) Salias = "" sfilename = "" End Sub

'Pause PUBLIC SUB MMPAUSE () DIM NRETURN As long if salias = "" "" "" "& salias,", " , 0, 0) End If 'NPosition = POSIOND SUB' Play Public Sub MMPLAY () DIM NRETURN As Long if Salias = "" The EXIT SUB ELSEIF POSITION = Length Then 'If you have already arrived MMSeek 0' jump to the beginning END IF If bwait kilton = mcIndstring ("Play" & Salias & "Wait", "", 0, 0) Else Nreturn = McIndstring ("Play" & Salias, ", 0, 0) end ifend sub

The 'Stop' stops and jumps to the beginning so that public sub mmstop () Dim Nreturn as long if salias = "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" Go to the start position END SUB

'Skip to the specified location, and is in the Pause Status' When NPosition> LENGTH or NPOSITION <0, this operation will ignore this operation PUBLIC SUB MMSEEK (Byval NPosition As Single) Dim Nreturn As Long Nreturn = McIndString ("Seek" & Salias & "To" & nPosition, "", 0, 0)

End Sub

'Method FileName Returns the currently open file name Property get filename () as string filename = sfilenamend property

'Specify the file name to play, then open it' For the AVI file that needs to specify the container, do not open in this way. Property Let FileName (Byval Sthefile As String)

Mmopen Sthefilend Property

'Read the value of the attribute WAIT' msgbox multimedia.waitproperty get Wait () as boolean wait = BWAITEND Property

'Setting waiting attribute' Usage: multimedia.wait = trueProperty Let Wait (BWAITVALUE As Boolean)

BWAIT = BWAITVALUEEND PROPERTY 'Getting length value Property Get Length () AS Single Dim Nreturn As Long, NLENGTH AS INTEGER

Dim Slength As String * 255 if salias = "" "THENGTH = 0 EXITPERTY END IF

Nreturn = McIndstring ("Status" & Salias & "Length", SLENGTH, 255, 0) NLENGTH = INSTR (SLENGTH, CHR $ (0)) Length = VAL (Left $ (SLENGTH, NLENGTH - 1)) End Property

Property Let Position (Byval NPosition As Single) MMSeek NPSIOND Property

'Get the current location Property Get Position () AS Single Dim Nreturn AS Integer, NLENGTH AS INTEGER DIM Spption AS String * 255

If salias = "" "" Status "& Salias &" Position ", Sposition, 255, 0) NLENGTH = INSTR (sposition, chr $ (0)) Position = VAL (SPSITION, NLENGTH - 1))

End Property

'The status of the current open file' has the following: Playing Paused StoppedProperty Get Status () AS STRING DIM NRETURN AS INTEGER, NLENGTH AS INTEGER DIM SSTATUS AS STRING * 255

If salias = "" "the EXIT Property

NRETURN = McIndstring ("Status" & Salias & "Mode", SSTATUS, 255, 0) NLENGTH = INSTR (Sstatus, Chr $ (0)) status = left $ (sstatus, nlength - 1) End Property

'From the beginning to play Public Sub mmrestart () DIM NRETURN As Long if salias = "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "

'Initialization private sub class_initialize ()' salias = "" The first value is empty END SUB

'Closing the Open Multimedia Device' When the object (or module) of the object is uninstalled, the process is automatically called the process private sub class_terminate () mmclosend sub '--------------- ------------------------------------- [usage] 1, such as playing one on the form Animation, just 3 statements will be made. DIM MMAVI AS New MMEDIAMMAVI.MMOPEN "g: /Resource/avi/test.avi", me.hwndmavi.mmmplay2, loop play private sub timer1_timer () DIM S AS STRING S = "Current File:" & mmavi.FileName & VBCRLF & "Current position:" & mmavi.position _ & "total length:" & mmavi.Length & "Current status:" & mmavi.status label1.caption = s if mmavi.status = "stopped" kilmavi.mmrestAnd Sub

3, play a few files at the same time (the type can be the same, can be different) Add Private mmwave (1) as new mmedia in Form1 plus: mmwave (0) .mmopen "G: / Resource / Wave / M16 .wav "MMWAVE (1) .mmopen" g: /resource/wave/welcom98.wav "mmwave (0) .MMPLAY MMWAVE (1) .MMPLAY4, put animation into a circular area play

DIM HR AS Long Dim UseW &, Useh & Dim Mmavi as New MMEDIA

usew & = Frame1.Width / Screen.TwipsPerPixelX useh & = Frame1.Height / Screen.TwipsPerPixelY usew = useh hr & = CreateEllipticRgn (0, 0, usew, useh) Call SetWindowRgn (Frame1.hWnd, hr, True) MmAvi.mmOpen "G: /Resource/avi/start.avi ", frame1.hwnd mmavi.mmmplay ..................................

转载请注明原文地址:https://www.9cbs.com/read-3221.html

New Post(0)