AVIファイルの再生(T)          <TOP>


AVIファイルを再生します。

mciSendString 文字列を MCI に送信

mciGetErrorString MCIエラーコードを記述する文字列を取得

GetShortPathName ファイルの短い形式のパス名を取得

 

ボタンでAVIファイルを選択し、 ボタンで再生します。

参照

AVIファイルの再生(U)

 

'================================================================
'= AVIファイルの再生
'=    (mciSendString.bas)
'================================================================
#include "Windows.bi"

' 文字列を MCI に送信
Declare Function Api_mciSendString& Lib "winmm" Alias "mciSendStringA" (ByVal lpstrCommand$, ByVal lpstrReturnString$, ByVal uReturnLength&, ByVal hwndCallback&)

' MCIエラーコードを記述する文字列を取得
Declare Function Api_mciGetErrorString& Lib "winmm" Alias "mciGetErrorStringA" (ByVal dwError&, ByVal lpstrBuffer$, ByVal uLength&)

' ファイルの短い形式のパス名を取得
Declare Function Api_GetShortPathName& Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath$, ByVal lpszShortPath$, ByVal lBuffer&)

#define WS_CHILD &H40000000             '親ウインドウを持つコントロール(子ウインドウ)を作成する

Var Shared Text1 As Object
Var Shared Button1 As Object
Var Shared Button2 As Object
Var Shared Picture1 As Object

Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 12
Button1.Attach GetDlgItem("Button1") : button1.SetFontSize 14
Button2.Attach GetDlgItem("Button2") : button2.SetFontSize 14
Picture1.Attach GetDlgItem("Picture1")

Var Shared FileName As String

'================================================================
'=
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()

    FileName = WinOpenDlg("ファイルのオープン","C:\*.avi","全てのファイル(*.avi)", 0)
    If FileName <> Chr$(&H1B) Then
        Text1.SetWindowText FileName
    End If
End Sub

'================================================================
'=
'================================================================
Declare Sub Button2_on edecl ()
Sub Button2_on()
    Var CommandString As String
    Var ShortFileName As String * 260
    Var deviceIsOpen As Integer
    Var Ret As Long

    FileName = GetDlgItemText("Text1")

    Ret = Api_GetShortPathName(FileName, ShortFileName, Len(ShortFileName))
    FileName = Left$(ShortFileName, Ret)

    '/ デバイスオープン
    CommandString = "Open " & FileName & " Type AVIVideo Alias AVIFile parent " & Str$(Picture1.GethWnd) & " style " & Str$(WS_CHILD)
    Ret = Api_mciSendString(CommandString, ByVal 0, 0, 0)
    If Ret Then goto *Err_Trap

    deviceIsOpen = True

    '/ ピクチャボックスサイズに合わせる
    CommandString = "put AVIFile window at 0 0 " & Str$(Picture1.GetWidth ) & " " & Str$(Picture1.GetHeight)
    Ret = Api_mciSendString(CommandString, ByVal 0, 0, 0)
    If Ret <> 0 Then goto *Err_Trap

    '/ ファイル再生
    CommandString = "Play AVIFile wait"
    Ret = Api_mciSendString(CommandString, ByVal 0, 0, 0)
    If Ret <> 0 Then goto *Err_Trap

    '/ デバイスクローズ
    CommandString = "Close AVIFile"
    Ret = Api_mciSendString(CommandString, ByVal 0, 0, 0)
    If Ret <> 0 Then goto *Err_Trap

    Exit Sub

*Err_Trap
    Var ErrorString As String
    ErrorString = space$(256)
    Ret = Api_mciGetErrorString(Ret, ErrorString, Len(ErrorString))
    ErrorString = Left$(ErrorString, InStr(ErrorString, Chr$(0)) - 1)

    If deviceIsOpen Then
        CommandString = "Close AVIFile"
        Ret = Api_mciSendString(CommandString, ByVal 0, 0, 0)
    End If
End Sub

'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End