大学IT网 - 最懂大学生的IT学习网站! QQ资料交流群:367606806
当前位置:大学IT网 > C#技巧 > c# Winform播放mp4视频

c# Winform播放mp4视频(1)

关键词:播放mp4mp4视频c#Winform  阅读(7501) 赞(17)

[摘要]本文是对c# 海康威视 Winform播放mp4视频的讲解,对学习C#编程技术有所帮助,与大家分享。

最近有个视频播放系统,需要对海康的mp4格式视频进行播放,由于普通播放器无法对该视频进行播放原因是海康对视频进行了自己的编码,需要相应的解码才可以对视频进行播放。

下面是对海康威视视频播放的c#代码(需要从海康官网下载播放库)。

一,这个是核心库通过c#对海康提供的动态链接库dll方法的封装。

 public class PlayCtrlSDK
     {
         #region 解码库
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern uint PlayM4_GetLastError(int nPort);
         /// <summary>
         /// 获取文件当前播放位置(百分比)。
         /// </summary>
         /// <param name="nPort"></param>
         /// <returns></returns>
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern float PlayM4_GetPlayPos(int nPort);
         /// <summary>
         ///设置文件当前播放位置(百分比)。
         /// </summary>
         /// <param name="nPort"></param>
         /// <returns></returns>
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern float PlayM4_SetPlayPos(int nPort, float fRelativePos);
         /// <summary>
         /// 获取文件大小
         /// </summary>
         /// <returns></returns>
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern uint PlayM4_GetFileHeadLength();
         /// <summary>
         /// 获取文件总时间 
         /// </summary>
         /// <param name="nPort"></param>PlayM4_GetPlayedTime
         /// <returns></returns>
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern uint PlayM4_GetFileTime(int nPort);
         /// <summary>
         /// 获取当前播放时间 
         /// </summary>
         /// <param name="nPort"></param>
         /// <returns></returns>
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern uint PlayM4_GetPlayedTime(int nPort);
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern int PlayM4_GetCaps();
         /// <summary>
         /// 关闭声音
         /// </summary>
         /// <returns></returns>
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern bool PlayM4_StopSound();
         /// <summary>
         /// 获取未使用的通道号
         /// </summary>
         /// <param name="nPort"></param>
         /// <returns></returns>
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern bool PlayM4_GetPort(ref int nPort);
         /// <summary>
         ///播放声音
         /// </summary>
         /// <param name="nPort"></param>
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern bool PlayM4_PlaySound(int nPort);
         /// <summary>
         /// 设置流播放模式
         /// </summary>
         /// <param name="port"></param>
         /// <param name="mode"></param>
         /// <returns></returns>
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern bool PlayM4_SetStreamOpenMode(int nPort, int mode);
         /// <summary>
         /// 打开流
         /// </summary>
         /// <param name="nPort"></param>
         /// <param name="pFileHeadBuf"></param>
         /// <param name="nSize"></param>
         /// <param name="nBufPoolSize"></param>
         /// <returns></returns>
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern bool PlayM4_OpenStream(int nPort, byte[] pFileHeadBuf, UInt32 nSize, uint nBufPoolSize);
         /// <summary>
         /// 设置播放缓冲区最大缓冲帧数
         /// </summary>
         /// <param name="nPort"></param>
         /// <param name="nNum"></param>
         /// <returns></returns>
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern bool PlayM4_SetDisplayBuf(int nPort, uint nBufPoolSize);
         /// <summary>
         /// 打开文件
         /// </summary>
         /// <param name="nPort"></param>
         /// <param name="hWnd"></param>
         /// <returns></returns>
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern bool PlayM4_OpenFile(int nPort, string fileName);
         /// <summary>
         /// 关闭文件
         /// </summary>
         /// <param name="nPort"></param>
         /// <param name="hWnd"></param>
         /// <returns></returns>
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern bool PlayM4_CloseFile(int nPort);
         /// <summary>
         /// 开启播放
         /// </summary>
         /// <param name="nPort"></param>
         /// <param name="hWnd"></param>
         /// <returns></returns>
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern bool PlayM4_Play(int nPort, IntPtr hWnd);
         /// <summary>
         /// 开始倒放
         /// </summary>
         /// <param name="nPort"></param>
         /// <returns></returns>
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern bool PlayM4_ReversePlay(int nPort);
         /// <summary>
         /// 输入流数据
         /// </summary>
         /// <param name="nPort"></param>
         /// <param name="pBuf"></param>
         /// <param name="nSize"></param>
         /// <returns></returns>
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern bool PlayM4_InputData(int nPort, byte[] pBuf, uint nSize);
         /// <summary>
         /// 关闭播放
         /// </summary>
         /// <param name="nPort"></param>
         /// <returns></returns>PlayM4_Pause
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern bool PlayM4_Stop(int nPort);
         /// <summary>
         ///暂停/播放1:暂停,0:恢复 
         /// </summary>
         /// <param name="nPort"></param>
         /// <returns></returns>
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern bool PlayM4_Pause(int nPort, uint nPause);
         /// <summary>
         /// 关闭流
         /// </summary>
         /// <param name="nPort"></param>
         /// <returns></returns>
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern bool PlayM4_CloseStream(int nPort);
         /// <summary>
         /// 释放已使用的通道号
         /// </summary>
         /// <param name="nPort"></param>
         /// <returns></returns>
         [SecurityCritical]
         [DllImport("PlayCtrl.dll")]
         public static extern bool PlayM4_FreePort(int nPort);
 
         #endregion
     }
«上一页12下一页»


相关评论