视频、图片连续循环播放

  1 None.gif
  2 None.gif ' 公共属性
  3 None.gif
  4 ExpandedBlockStart.gifContractedBlock.gif Public   Class Common Class Common
  5InBlock.gif    Private _fileType As String        '播放类型
  6ExpandedSubBlockStart.gifContractedSubBlock.gif    Public Property fileType()Property fileType() As String
  7InBlock.gif        Get
  8InBlock.gif            fileType = _fileType
  9InBlock.gif        End Get
 10InBlock.gif        Set(ByVal value As String)
 11InBlock.gif            _fileType = value
 12InBlock.gif        End Set
 13ExpandedSubBlockEnd.gif    End Property

 14InBlock.gif    Private _fileName As String      '播放文件名
 15ExpandedSubBlockStart.gifContractedSubBlock.gif    Public Property fileName()Property fileName() As String
 16InBlock.gif        Get
 17InBlock.gif            fileName = _fileName
 18InBlock.gif        End Get
 19InBlock.gif        Set(ByVal value As String)
 20InBlock.gif            _fileName = value
 21InBlock.gif        End Set
 22ExpandedSubBlockEnd.gif    End Property

 23InBlock.gif    Private _width As Integer        '宽度
 24ExpandedSubBlockStart.gifContractedSubBlock.gif    Public Property width()Property width() As Integer
 25InBlock.gif        Get
 26InBlock.gif            width = _width
 27InBlock.gif        End Get
 28InBlock.gif        Set(ByVal value As Integer)
 29InBlock.gif            _width = value
 30InBlock.gif        End Set
 31ExpandedSubBlockEnd.gif    End Property

 32InBlock.gif    Private _height As Integer       '高度
 33ExpandedSubBlockStart.gifContractedSubBlock.gif    Public Property height()Property height() As Integer
 34InBlock.gif        Get
 35InBlock.gif            height = _height
 36InBlock.gif        End Get
 37InBlock.gif        Set(ByVal value As Integer)
 38InBlock.gif            _height = value
 39InBlock.gif        End Set
 40ExpandedSubBlockEnd.gif    End Property

 41InBlock.gif    Private _playTime As Integer     '播放时间
 42ExpandedSubBlockStart.gifContractedSubBlock.gif    Public Property playTime()Property playTime() As Integer
 43InBlock.gif        Get
 44InBlock.gif            playTime = _playTime
 45InBlock.gif        End Get
 46InBlock.gif        Set(ByVal value As Integer)
 47InBlock.gif            _playTime = value
 48InBlock.gif        End Set
 49ExpandedSubBlockEnd.gif    End Property

 50InBlock.gif    Private _scale As Integer        '缩放比例
 51ExpandedSubBlockStart.gifContractedSubBlock.gif    Public Property scale()Property scale() As Integer
 52InBlock.gif        Get
 53InBlock.gif            scale = _scale
 54InBlock.gif        End Get
 55InBlock.gif        Set(ByVal value As Integer)
 56InBlock.gif            _scale = value
 57InBlock.gif        End Set
 58ExpandedSubBlockEnd.gif    End Property

 59InBlock.gif    Private _playCount As Integer    '播放次数
 60ExpandedSubBlockStart.gifContractedSubBlock.gif    Public Property playCount()Property playCount() As Integer
 61InBlock.gif        Get
 62InBlock.gif            playCount = _playCount
 63InBlock.gif        End Get
 64InBlock.gif        Set(ByVal value As Integer)
 65InBlock.gif            _playCount = value
 66InBlock.gif        End Set
 67ExpandedSubBlockEnd.gif    End Property

 68InBlock.gif
 69InBlock.gif
 70InBlock.gif    Private _ISPLAY As String       '是否播放 
 71ExpandedSubBlockStart.gifContractedSubBlock.gif    Public Property ISPLAY()Property ISPLAY() As String
 72InBlock.gif        Get
 73InBlock.gif            ISPLAY = _ISPLAY
 74InBlock.gif        End Get
 75InBlock.gif        Set(ByVal value As String)
 76InBlock.gif            _ISPLAY = value
 77InBlock.gif        End Set
 78ExpandedSubBlockEnd.gif    End Property

 79InBlock.gif    Private _filePath As String     '播放文件的路径
 80ExpandedSubBlockStart.gifContractedSubBlock.gif    Public Property filePath()Property filePath() As String
 81InBlock.gif        Get
 82InBlock.gif            filePath = _filePath
 83InBlock.gif        End Get
 84InBlock.gif        Set(ByVal value As String)
 85InBlock.gif            _filePath = value
 86InBlock.gif        End Set
 87ExpandedSubBlockEnd.gif    End Property

 88InBlock.gif    Private _playNum As Integer     '播放序号
 89ExpandedSubBlockStart.gifContractedSubBlock.gif    Public Property playNum()Property playNum() As Integer
 90InBlock.gif        Get
 91InBlock.gif            playNum = _playNum
 92InBlock.gif        End Get
 93InBlock.gif        Set(ByVal value As Integer)
 94InBlock.gif            _playNum = value
 95InBlock.gif        End Set
 96ExpandedSubBlockEnd.gif    End Property

 97InBlock.gif    Private _playFlag As Boolean    '是否播放
 98ExpandedSubBlockStart.gifContractedSubBlock.gif    Public Property playFlag()Property playFlag() As Boolean
 99InBlock.gif        Get
100InBlock.gif            playFlag = _playFlag
101InBlock.gif        End Get
102InBlock.gif        Set(ByVal value As Boolean)
103InBlock.gif            _playFlag = value
104InBlock.gif        End Set
105ExpandedSubBlockEnd.gif    End Property

106InBlock.gif
107ExpandedBlockEnd.gifEnd Class

108 None.gif

  1 ExpandedBlockStart.gif ContractedBlock.gif Public   Class frmMain Class frmMain
  2InBlock.gif
  3InBlock.gif    Dim comm As New Common()
  4InBlock.gif    Dim myopXML As New opXML()
  5InBlock.gif    Dim myTime As Integer
  6InBlock.gif    Dim st As Stopwatch = New Stopwatch()
  7InBlock.gif    Dim flag As String      '循环播放标志
  8InBlock.gif
  9ExpandedSubBlockStart.gifContractedSubBlock.gif    Private Sub frmMain_Load()Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 10InBlock.gif        PlayLoad()                      '加载播放
 11InBlock.gif        Me.Timer1.Enabled = True        '记时器可用状态
 12InBlock.gif        comm.playNum = 0
 13ExpandedSubBlockEnd.gif            End Sub

 14ExpandedSubBlockStart.gifContractedSubBlock.gif  Private Sub PlayLoad()Sub PlayLoad()
 15InBlock.gif        myopXML.GetSysNodeValue(comm.ISPLAY, comm.filePath, myPort)
 16InBlock.gif        If comm.ISPLAY.ToUpper() = "Y" Then       '是否播放
 17InBlock.gif            myopXML.GetAdNodeValue(comm.fileType, comm.fileName, comm.width, comm.height, comm.playTime, comm.scale, comm.playCount, comm.playNum, flag)
 18InBlock.gif            If flag.ToUpper() = "Y" Then        '如果是循环,则将播放序号置为0(即从第一个开始播放)
 19InBlock.gif                comm.playNum = 0
 20InBlock.gif                PlayLoad()                      '循环播放
 21InBlock.gif            ElseIf My.Computer.FileSystem.DirectoryExists(comm.filePath) = True Then    '如果播放文件的目录存在
 22InBlock.gif                If My.Computer.FileSystem.FileExists(comm.filePath + comm.fileName) Then    '如果文件存在
 23InBlock.gif                    If comm.fileType = "pic" Then           '如果是图片
 24InBlock.gif                        Me.PictureBox1.Visible = True
 25InBlock.gif                        Dim myImage As Bitmap
 26InBlock.gif                        myImage = New Bitmap(comm.filePath + comm.fileName)
 27InBlock.gif                        Me.PictureBox1.SizeMode = PictureBoxSizeMode.Zoom '.Normal '.StretchImage 'toSize '.StretchImage '.Normal '.CenterImage
 28InBlock.gif                        'Me.PictureBox1.ClientSize = New Size(200, 200)   '显示大小
 29InBlock.gif                        Me.PictureBox1.Width = comm.width
 30InBlock.gif                        Me.PictureBox1.Height = comm.height
 31InBlock.gif                        'me.PictureBox1.Scale(
 32InBlock.gif                        Me.PictureBox1.Image = CType(myImage, Image)
 33InBlock.gif                        st.Start()  '记时开始
 34InBlock.gif
 35InBlock.gif                    ElseIf comm.fileType = "video" Then     '如果是视频
 36InBlock.gif                        Me.AxWindowsMediaPlayer1.Visible = True
 37InBlock.gif                        Me.AxWindowsMediaPlayer1.Width = comm.width
 38InBlock.gif                        Me.AxWindowsMediaPlayer1.Height = comm.height
 39InBlock.gif                        Me.AxWindowsMediaPlayer1.URL = comm.filePath + comm.fileName
 40InBlock.gif                        st.Start()
 41InBlock.gif                    End If
 42InBlock.gif
 43InBlock.gif                    'Me.Label3.Text = comm.fileName + " is playingdot.gif"  '测试用
 44InBlock.gif                Else
 45InBlock.gif                    comm.playNum += 1   '如果没找到播放文件,则播放下一个
 46InBlock.gif                    PlayLoad()          '继续下一个播放
 47InBlock.gif                End If
 48InBlock.gif
 49InBlock.gif            Else            '如果播放文件的目录不存在
 50InBlock.gif                My.Computer.FileSystem.CreateDirectory(comm.filePath)
 51InBlock.gif            End If
 52InBlock.gif
 53InBlock.gif
 54InBlock.gif            'Me.Label4.Text = comm.playNum + comm.playTime + comm.scale + comm.playCount
 55InBlock.gif        End If
 56ExpandedSubBlockEnd.gif    End Sub

 57InBlock.gif
 58ExpandedSubBlockStart.gifContractedSubBlock.gif    Private Sub AxWindowsMediaPlayer1_PlayStateChange()Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent)
 59InBlock.gif
 60InBlock.gif        'Me.Label3.Text = VideoPlayTime() 'playTime.ToString() + "/" + allTime + "/"  '测试用
 61ExpandedSubBlockEnd.gif    End Sub

 62InBlock.gif
 63InBlock.gif    '取时间 (xx:xx)
 64ExpandedSubBlockStart.gifContractedSubBlock.gif    Private Function VideoPlayTime()Function VideoPlayTime() As Integer
 65InBlock.gif        Dim allTime As String = Me.AxWindowsMediaPlayer1.currentMedia.durationString
 66InBlock.gif        Dim playTime As Integer = CType(allTime.Substring(0, allTime.IndexOf(":"0)), Integer* 60 _
 67InBlock.gif                                    + CType(allTime.Substring(allTime.IndexOf(":"0+ 12), Integer)     '取播放视频时间(秒)
 68InBlock.gif        'comm.playTime = playTime
 69InBlock.gif        Return playTime
 70ExpandedSubBlockEnd.gif    End Function

 71InBlock.gif
 72InBlock.gif    '播放记时
 73ExpandedSubBlockStart.gifContractedSubBlock.gif    Private Sub Timer1_Tick()Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
 74InBlock.gif        If st.IsRunning = True Then
 75InBlock.gif            ViewProcess()
 76InBlock.gif        End If
 77ExpandedSubBlockEnd.gif    End Sub

 78InBlock.gif
 79InBlock.gif    '播放处理
 80ExpandedSubBlockStart.gifContractedSubBlock.gif    Private Sub ViewProcess()Sub ViewProcess()
 81InBlock.gif        'Me.Label2.Text = st.Elapsed.TotalSeconds.ToString
 82InBlock.gif        If comm.fileType = "video" Then
 83InBlock.gif            If CType(st.Elapsed.TotalSeconds, Integer= comm.playTime Then     '到时间后就播放下一个文件VideoPlayTime()
 84InBlock.gif                Me.AxWindowsMediaPlayer1.Ctlcontrols.stop()         '停止播放
 85InBlock.gif                Me.AxWindowsMediaPlayer1.Visible = False            '隐藏控件 
 86InBlock.gif                st.Reset()                                         '记时重启
 87InBlock.gif                comm.playNum += 1                                   '播放序号加1
 88InBlock.gif                Me.PlayLoad()                                       '加载播放
 89InBlock.gif            End If
 90InBlock.gif        Else
 91InBlock.gif            If CType(st.Elapsed.TotalSeconds, Integer= comm.playTime Then
 92InBlock.gif                Me.PictureBox1.Visible = False                       '隐藏控件  
 93InBlock.gif                st.Reset()                                         '记时重启
 94InBlock.gif                comm.playNum += 1                                   '播放序号加1
 95InBlock.gif                Me.PlayLoad()                                       '加载播放
 96InBlock.gif            End If
 97InBlock.gif        End If
 98InBlock.gif
 99ExpandedSubBlockEnd.gif    End Sub

100InBlock.gif
101InBlock.gif   '窗体控件缩变
102ExpandedSubBlockStart.gifContractedSubBlock.gif    Private Sub frmMain_Resize()Sub frmMain_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
103InBlock.gif        Me.SplitContainer1.Width = 800 / 800 * Me.Width
104InBlock.gif        Me.SplitContainer1.Height = 600 / 600 * Me.Height
105InBlock.gif        Me.PictureBox1.Width = comm.width / 800 * Me.Width
106InBlock.gif        Me.PictureBox1.Height = comm.height / 600 * Me.Height
107InBlock.gif        Me.AxWindowsMediaPlayer1.Width = comm.width / 800 * Me.Width
108InBlock.gif        Me.AxWindowsMediaPlayer1.Height = comm.height / 600 * Me.Height
109ExpandedSubBlockEnd.gif    End Sub

 1 ExpandedBlockStart.gif ContractedBlock.gif Public   Class opXML Class opXML
 2InBlock.gif    ''' <summary>
 3InBlock.gif    ''' 取播放信息
 4InBlock.gif    ''' </summary>
 5InBlock.gif    ''' <param name="fileType"></param>
 6InBlock.gif    ''' <param name="fileName"></param>
 7InBlock.gif    ''' <param name="width"></param>
 8InBlock.gif    ''' <param name="height"></param>
 9InBlock.gif    ''' <param name="playTime"></param>
10InBlock.gif    ''' <param name="scale"></param>
11InBlock.gif    ''' <param name="playCount">播放次数</param>
12InBlock.gif    ''' <param name="playNum">序号</param>
13InBlock.gif    ''' <remarks></remarks>
14ExpandedSubBlockStart.gifContractedSubBlock.gif    Public Sub GetAdNodeValue()Sub GetAdNodeValue(ByRef fileType As StringByRef fileName As String, _
15InBlock.gif                                 ByRef width As IntegerByRef height As Integer, _
16InBlock.gif                                 ByRef playTime As IntegerByRef scale As Integer, _
17InBlock.gif                                 ByRef playCount As IntegerByRef playNum As IntegerByRef flag As String)
18InBlock.gif        'If playNum Is Nothing Then
19InBlock.gif
20InBlock.gif        'End If
21InBlock.gif        Dim xmlDoc As New Xml.XmlDocument()
22InBlock.gif        xmlDoc.Load("adList.xml")
23InBlock.gif        Dim nodeList As Xml.XmlNodeList = xmlDoc.SelectSingleNode("adList").ChildNodes
24InBlock.gif        'While playNum < nodeList.Count
25InBlock.gif        If playNum <= nodeList.Count - 1 Then    '检查序号是否合法(即在有效范围内)
26InBlock.gif            If Not nodeList.Item(playNum).Name Is Nothing Then  '判断结点是否存在
27InBlock.gif                fileType = nodeList.Item(playNum).Item("fileType").InnerText
28InBlock.gif                fileName = nodeList.Item(playNum).Item("fileName").InnerText
29InBlock.gif                width = nodeList.Item(playNum).Item("width").InnerText
30InBlock.gif                height = nodeList.Item(playNum).Item("height").InnerText
31InBlock.gif                playTime = nodeList.Item(playNum).Item("playTime").InnerText
32InBlock.gif                playCount = nodeList.Item(playNum).Item("playCount").InnerText
33InBlock.gif                flag = "N"
34InBlock.gif                'playNum += 1
35InBlock.gif            End If
36InBlock.gif        Else                    '否则循环
37InBlock.gif            flag = "Y"
38InBlock.gif        End If
39InBlock.gif
40InBlock.gif
41InBlock.gif        'End While
42InBlock.gif        '
43ExpandedSubBlockEnd.gif    End Sub

44InBlock.gif
45InBlock.gif    ''' <summary>
46InBlock.gif    ''' 取系统设置参数
47InBlock.gif    ''' </summary>
48InBlock.gif    ''' <param name="ISPLAY"></param>
49InBlock.gif    ''' <param name="filePath"></param>
50InBlock.gif    ''' <remarks></remarks>
51ExpandedSubBlockStart.gifContractedSubBlock.gif    Public Sub GetSysNodeValue()Sub GetSysNodeValue(ByRef ISPLAY As StringByRef filePath As StringByRef myPort As Integer)
52InBlock.gif        Dim xmlDoc As New Xml.XmlDocument()
53InBlock.gif        xmlDoc.Load("sys.xml")
54InBlock.gif        Dim nodeList As Xml.XmlNodeList = xmlDoc.SelectSingleNode("sys").ChildNodes
55InBlock.gif        If Not nodeList.Item(0).Name Is Nothing Then  '判断结点是否存在
56InBlock.gif            ISPLAY = nodeList.Item(0).Item("ISPLAY").InnerText
57InBlock.gif            filePath = nodeList.Item(0).Item("filePath").InnerText
58InBlock.gif            myPort = CType(nodeList.Item(0).Item("Port").InnerText, Integer)
59InBlock.gif        End If
60ExpandedSubBlockEnd.gif    End Sub

61ExpandedBlockEnd.gifEnd Class

62 None.gif

 1 None.gif <? xml version="1.0" encoding="gb2312" ?>
 2 None.gif < sys >
 3 None.gif   < set >
 4 None.gif     < ISPLAY  intro ="是否播放:Y否,N是" > Y </ ISPLAY >
 5 None.gif     < IP  intro ="目标机的IP" > 192.0.3.33 </ IP >
 6 None.gif     < Port  intro ="目标机端口号" > 34567 </ Port >
 7 None.gif     < filePath  intro ="媒体文件路径" > c:\adFile\ </ filePath >
 8 None.gif     < date  intro ="日期" > 2007209 </ date >
 9 None.gif     < version  intro ="版本号" > 01 </ version >
10 None.gif   </ set >
11 None.gif </ sys >

 1 None.gif <? xml version="1.0" encoding="gb2312" ?>
 2 None.gif < adList >
 3 None.gif   < file >
 4 None.gif     < fileType  intro ="" > pic </ fileType >
 5 None.gif     < fileName  intro ="播放文件名" > 1.jpg </ fileName >
 6 None.gif     < width  intro ="宽度" > 800 </ width >
 7 None.gif     < height  intro ="高度" > 600 </ height >
 8 None.gif     < playTime  intro ="播放时间" > 4 </ playTime >
 9 None.gif     < scale  intro ="缩放比例" > 0 </ scale >
10 None.gif     < playCount  intro ="播放次数" > 1 </ playCount >
11 None.gif  </ file >
12 None.gif   < file >
13 None.gif     < fileType  intro ="" > pic </ fileType >
14 None.gif     < fileName  intro ="播放文件名" > 2.jpg </ fileName >
15 None.gif     < width  intro ="宽度" > 800 </ width >
16 None.gif     < height  intro ="高度" > 600 </ height >
17 None.gif     < playTime  intro ="播放时间" > 4 </ playTime >
18 None.gif     < scale  intro ="缩放比例" > 0 </ scale >
19 None.gif     < playCount  intro ="播放次数" > 1 </ playCount >
20 None.gif  </ file >
21 None.gif   < file >
22 None.gif     < fileType  intro ="" > pic </ fileType >
23 None.gif     < fileName  intro ="播放文件名" > 30.jpg </ fileName >
24 None.gif     < width  intro ="宽度" > 1024 </ width >
25 None.gif     < height  intro ="高度" > 768 </ height >
26 None.gif     < playTime  intro ="播放时间" > 4 </ playTime >
27 None.gif     < scale  intro ="缩放比例" > 0 </ scale >
28 None.gif     < playCount  intro ="播放次数" > 1 </ playCount >
29 None.gif  </ file >
30 None.gif  < file >
31 None.gif     < fileType  intro ="" > video </ fileType >
32 None.gif     < fileName  intro ="播放文件名" > 1.wmv </ fileName >
33 None.gif     < width  intro ="宽度" > 800 </ width >
34 None.gif     < height  intro ="高度" > 600 </ height >
35 None.gif     < playTime  intro ="播放时间" > 15 </ playTime >
36 None.gif     < scale  intro ="缩放比例" > 0 </ scale >
37 None.gif     < playCount  intro ="播放次数" > 1 </ playCount >
38 None.gif  </ file >
39 None.gif   < file >
40 None.gif     < fileType  intro ="" > pic </ fileType >
41 None.gif     < fileName  intro ="播放文件名" > 4.jpg </ fileName >
42 None.gif     < width  intro ="宽度" > 800 </ width >
43 None.gif     < height  intro ="高度" > 600 </ height >
44 None.gif     < playTime  intro ="播放时间" > 4 </ playTime >
45 None.gif     < scale  intro ="缩放比例" > 0 </ scale >
46 None.gif     < playCount  intro ="播放次数" > 1 </ playCount >
47 None.gif  </ file >
48 None.gif < file >
49 None.gif     < fileType  intro ="" > video </ fileType >
50 None.gif     < fileName  intro ="播放文件名" > 1.swf </ fileName >
51 None.gif     < width  intro ="宽度" > 800 </ width >
52 None.gif     < height  intro ="高度" > 600 </ height >
53 None.gif     < playTime  intro ="播放时间" > 15 </ playTime >
54 None.gif     < scale  intro ="缩放比例" > 0 </ scale >
55 None.gif     < playCount  intro ="播放次数" > 1 </ playCount >
56 None.gif  </ file > 57 None.gif
58 None.gif  </ adList >

转载于:https://www.cnblogs.com/yongwnet/archive/2007/02/09/646471.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值