视频、图片连续循环播放

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

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

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

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

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

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

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

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

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

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

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

106
107End Class

108

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

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

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

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

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

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

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

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

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

61End Class

62

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

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