コード例 #1
0
ファイル: VLCPlayer.cs プロジェクト: sxfxhqq/HSTDetect
        /// <summary>
        /// 创建VLC播放资源索引
        /// </summary>
        /// <param name="arguments"></param>
        /// <returns></returns>
        private libvlc_instance_t Create_Media_Instance()
        {
            libvlc_instance_t libvlc_instance = IntPtr.Zero;
            IntPtr            argvPtr         = IntPtr.Zero;

            try
            {
                if (arguments.Length == 0 ||
                    arguments == null)
                {
                    return(IntPtr.Zero);
                }

                //将string数组转换为指针
                argvPtr = StrToIntPtr(arguments);
                if (argvPtr == null || argvPtr == IntPtr.Zero)
                {
                    return(IntPtr.Zero);
                }

                //设置启动参数
                libvlc_instance = SafeNativeMethods.libvlc_new(arguments.Length, argvPtr);
                if (libvlc_instance == null || libvlc_instance == IntPtr.Zero)
                {
                    return(IntPtr.Zero);
                }

                return(libvlc_instance);
            }
            catch
            {
                return(IntPtr.Zero);
            }
        }
コード例 #2
0
ファイル: VLCPlayer.cs プロジェクト: sxfxhqq/HSTDetect
        /// <summary>
        /// 创建VLC播放器
        /// </summary>
        /// <param name="libvlc_instance">VLC 全局变量</param>
        /// <param name="handle">VLC MediaPlayer需要绑定显示的窗体句柄</param>
        /// <returns></returns>
        private libvlc_media_player_t Create_MediaPlayer(libvlc_instance_t libvlc_instance, IntPtr handle)
        {
            libvlc_media_player_t libvlc_media_player = IntPtr.Zero;

            try
            {
                if (libvlc_instance == IntPtr.Zero ||
                    libvlc_instance == null ||
                    handle == IntPtr.Zero ||
                    handle == null)
                {
                    return(IntPtr.Zero);
                }

                //创建播放器
                libvlc_media_player = SafeNativeMethods.libvlc_media_player_new(libvlc_instance);
                if (libvlc_media_player == null || libvlc_media_player == IntPtr.Zero)
                {
                    return(IntPtr.Zero);
                }

                //设置播放窗口
                SafeNativeMethods.libvlc_media_player_set_hwnd(libvlc_media_player, (int)handle);

                return(libvlc_media_player);
            }
            catch
            {
                SafeNativeMethods.libvlc_media_player_release(libvlc_media_player);

                return(IntPtr.Zero);
            }
        }
コード例 #3
0
ファイル: VLCPlayer.cs プロジェクト: sxfxhqq/HSTDetect
        /// <summary>
        /// 播放本地视频
        /// </summary>
        /// <param name="libvlc_instance"></param>
        /// <param name="libvlc_media_player"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        private bool Local_Media_Play(libvlc_instance_t libvlc_instance, libvlc_media_player_t libvlc_media_player, string url)
        {
            IntPtr         pMrl         = IntPtr.Zero;
            libvlc_media_t libvlc_media = IntPtr.Zero;

            try
            {
                if (url == null ||
                    libvlc_instance == IntPtr.Zero ||
                    libvlc_instance == null ||
                    libvlc_media_player == IntPtr.Zero ||
                    libvlc_media_player == null)
                {
                    return(false);
                }

                pMrl = StrToIntPtr(url);
                if (pMrl == null || pMrl == IntPtr.Zero)
                {
                    return(false);
                }

                //播放本地视频
                libvlc_media = SafeNativeMethods.libvlc_media_new_path(libvlc_instance, pMrl);

                if (libvlc_media == null || libvlc_media == IntPtr.Zero)
                {
                    return(false);
                }

                //将Media绑定到播放器上
                SafeNativeMethods.libvlc_media_player_set_media(libvlc_media_player, libvlc_media);

                //释放libvlc_media资源
                SafeNativeMethods.libvlc_media_release(libvlc_media);
                libvlc_media = IntPtr.Zero;

                if (0 != SafeNativeMethods.libvlc_media_player_play(libvlc_media_player))
                {
                    return(false);
                }

                //休眠指定时间
                Thread.Sleep(500);

                return(true);
            }
            catch (Exception)
            {
                //释放libvlc_media资源
                if (libvlc_media != IntPtr.Zero)
                {
                    SafeNativeMethods.libvlc_media_release(libvlc_media);
                }
                libvlc_media = IntPtr.Zero;

                return(false);
            }
        }
コード例 #4
0
        private bool NetWork_Media_Play(libvlc_instance_t libvlc_instance, libvlc_media_player_t libvlc_media_player, string url)
        {
            IntPtr         pMrl         = IntPtr.Zero;
            libvlc_media_t libvlc_media = IntPtr.Zero;

            try
            {
                if (url == null ||
                    libvlc_instance == IntPtr.Zero ||
                    libvlc_instance == null ||
                    libvlc_media_player == IntPtr.Zero ||
                    libvlc_media_player == null)
                {
                    return(false);
                }

                pMrl = StrToIntPtr(url);
                if (pMrl == null || pMrl == IntPtr.Zero)
                {
                    return(false);
                }

                libvlc_media = SafeNativeMethods.libvlc_media_new_location(libvlc_instance, pMrl);

                if (libvlc_media == null || libvlc_media == IntPtr.Zero)
                {
                    return(false);
                }

                SafeNativeMethods.libvlc_media_player_set_media(libvlc_media_player, libvlc_media);

                SafeNativeMethods.libvlc_media_release(libvlc_media);
                libvlc_media = IntPtr.Zero;

                if (0 != SafeNativeMethods.libvlc_media_player_play(libvlc_media_player))
                {
                    return(false);
                }

                Thread.Sleep(500);

                return(true);
            }
            catch (Exception)
            {
                if (libvlc_media != IntPtr.Zero)
                {
                    SafeNativeMethods.libvlc_media_release(libvlc_media);
                }
                libvlc_media = IntPtr.Zero;

                return(false);
            }
        }
コード例 #5
0
        /// <summary>
        /// 录制网络媒体
        /// </summary>
        /// <param name="libvlc_instance">VLC 全局变量</param>
        /// <param name="url">网络视频URL,支持http、rtp、udp等格式的URL播放</param>
        /// <returns></returns>
        public bool NetWork_Media_Save(libvlc_instance_t libvlc_instance, string url)
        {
            IntPtr         pMrl         = IntPtr.Zero;
            libvlc_media_t libvlc_media = IntPtr.Zero;

            try
            {
                if (url == null ||
                    libvlc_instance == IntPtr.Zero ||
                    libvlc_instance == null)
                {
                    return(false);
                }

                pMrl = StrToIntPtr(url);
                if (pMrl == null || pMrl == IntPtr.Zero)
                {
                    return(false);
                }

                //播放网络文件
                libvlc_media = SafeNativeMethods.libvlc_media_new_location(libvlc_instance, pMrl);

                if (libvlc_media == null || libvlc_media == IntPtr.Zero)
                {
                    return(false);
                }

                //释放libvlc_media资源
                //SafeNativeMethods.libvlc_media_release(libvlc_media);
                //libvlc_media = IntPtr.Zero;

                //休眠指定时间
                //Thread.Sleep(200);

                return(true);
            }
            catch (Exception)
            {
                //释放libvlc_media资源
                if (libvlc_media != IntPtr.Zero)
                {
                    SafeNativeMethods.libvlc_media_release(libvlc_media);
                }
                libvlc_media = IntPtr.Zero;

                return(false);
            }
        }
コード例 #6
0
ファイル: VLCPlayer.cs プロジェクト: sxfxhqq/HSTDetect
        /// <summary>
        /// 释放VLC播放资源索引
        /// </summary>
        /// <param name="libvlc_instance">VLC 全局变量</param>
        private void Release_Media_Instance(libvlc_instance_t libvlc_instance)
        {
            try
            {
                if (libvlc_instance != IntPtr.Zero ||
                    libvlc_instance != null)
                {
                    SafeNativeMethods.libvlc_release(libvlc_instance);
                }

                libvlc_instance = IntPtr.Zero;
            }
            catch (Exception)
            {
                libvlc_instance = IntPtr.Zero;
            }
        }
コード例 #7
0
ファイル: libVLC.cs プロジェクト: buidan/dreamviewer
 static extern IntPtr libvlc_playlist_get_input(ref libvlc_instance_t libvlc, ref libvlc_exception_t p_exception);
コード例 #8
0
ファイル: VLCPlayer.cs プロジェクト: sxfxhqq/HSTDetect
 /// <summary>
 /// 播放网络视频流
 /// </summary>
 /// <param name="url">url地址</param>
 /// <param name="handle">显示控件句柄</param>
 /// <returns>true:播放成功;false:播放失败</returns>
 public bool playUrl(string url, IntPtr handle)
 {
     lit  = Create_Media_Instance();
     lmpt = Create_MediaPlayer(lit, handle);
     return(NetWork_Media_Play(lit, lmpt, url));
 }
コード例 #9
0
ファイル: VLCPlayer.cs プロジェクト: sxfxhqq/HSTDetect
 internal static extern libvlc_media_player_t libvlc_media_player_new(libvlc_instance_t libvlc_instance);
コード例 #10
0
ファイル: VLCPlayer.cs プロジェクト: sxfxhqq/HSTDetect
 internal static extern libvlc_media_t libvlc_media_new_path(libvlc_instance_t libvlc_instance, IntPtr path);
コード例 #11
0
ファイル: VLCPlayer.cs プロジェクト: sxfxhqq/HSTDetect
 internal static extern void libvlc_release(libvlc_instance_t libvlc_instance);
コード例 #12
0
ファイル: VLCPlayer.cs プロジェクト: sxfxhqq/HSTDetect
 /// <summary>
 /// 播放本地视频
 /// </summary>
 /// <param name="path">视频路径</param>
 /// <param name="handle">显示控件句柄</param>
 /// <returns>true:播放成功;false:播放失败</returns>
 public bool playLocalVideo(string path, IntPtr handle)
 {
     lit  = Create_Media_Instance();
     lmpt = Create_MediaPlayer(lit, handle);
     return(Local_Media_Play(lit, lmpt, path));
 }
コード例 #13
0
        private void LibVLCInit(string[] args)
        {
            IntPtr pLibVLC;
            libvlc_exception_t exp = new libvlc_exception_t();
            libvlc_exception_init(ref exp);

            pLibVLC = libvlc_new(args.Length, args, ref exp);
            if (0 != libvlc_exception_raised(ref exp))
            {
                //Console.WriteLine("Error: {0}", exp.psz_message);
                throw new Win32Exception(exp.psz_message);
            }
            else
            {
                _instanceVLC = (libvlc_instance_t)Marshal.PtrToStructure(pLibVLC, typeof(libvlc_instance_t));
                _pLibVLCHandle = pLibVLC;
                //Console.WriteLine("pLibVLC Done! - {0:X}", pLibVLC);
            }
        }
コード例 #14
0
			public VlcPlaylistObject(int vlcHandle)
				: base(vlcHandle, ObjectType.VLC_OBJECT_PLAYLIST)
			{
				if(this.SubObject != IntPtr.Zero)
				{
					this.libvlc = new libvlc_instance_t(this.Vlc, this.SubObject, vlcHandle);
					this.exception.Init();
				}
			}
コード例 #15
0
		static extern void libvlc_playlist_play(ref libvlc_instance_t libvlc, Int32 id, 
			Int32 optionsCount, IntPtr optionsAlwaysNull, ref libvlc_exception_t p_exception);