none
VSTO如何播放视频文件? RRS feed

  • 问题

  • 如题,我新建了Office 2010 Workbook之后,想在Sheet中加入PictureBox,然后在PictureBox中播放C盘的一个视频文件(T.avi),请问代码如何实现?

    我尝试了MciSendString,但是不会用,只能打开文件听到声音,但是不能播放出视频.

    谢谢大家!

    我现在的代码:

    类:

    Public Class AVIPlayer
        Private _command As String
        Private isOpen As Boolean
        <Runtime.InteropServices.DllImport("winmm.dll")> _
        Private Shared Function mciSendString(ByVal strCommand As String, _
            ByVal strReturn As System.Text.StringBuilder, _
            ByVal iReturnLength As Integer, _
            ByVal hwndCallback As IntPtr) As Long
        End Function
        Public Sub aviClose()
            _command = "close AVIVideo_alias"
            mciSendString(_command, Nothing, 0, IntPtr.Zero)
            isOpen = False
        End Sub
        Public Sub aviOpen(ByVal sFileName As String, ByVal Obj As Object)
            _command = "open """ + sFileName + """ type AVIVideo alias AVIVideo_alias style overlapped "
            mciSendString(_command, Nothing, 0, IntPtr.Zero)
            mciSendString("put Animation window at 10 10 200 200", Nothing, 0, IntPtr.Zero)
            isOpen = True
        End Sub
        Public Sub aviPlay(ByVal [loop] As Boolean)
            If isOpen Then
                _command = "play AVIVideo_alias"
                If [loop] Then
                    _command += " REPEAT"
                End If
                mciSendString(_command, Nothing, 0, IntPtr.Zero)
            End If
        End Sub
        Public Function aviSetVolume(ByVal v As Long) As Boolean
            If isOpen Then
                _command = "setaudio  AVIVideo_alias volume to " + v.ToString
                aviSetVolume = mciSendString(_command, Nothing, 0, 0)
            End If
        End Function
    End Class

    Sheet1中的button代码:

    Imports System.Runtime.InteropServices
    Public Class Sheet1
        Dim player As AVIPlayer
        Private Sub Sheet1_Startup() Handles Me.Startup
        End Sub
        Private Sub Sheet1_Shutdown() Handles Me.Shutdown
        End Sub
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            player = New AVIPlayer()
            player.aviOpen("C:\T.avi", PictureBox1)
            player.aviPlay(False)
        End Sub
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            player.aviClose()
        End Sub
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            player.aviSetVolume(100)
        End Sub
        Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        End Sub
    End Class




    • 已编辑 qdawgao 2012年6月6日 1:16
    2012年6月5日 8:56

全部回复