Пример #1
0
        public void Play(string filePath, IntPtr handle)
        {
            if (libvlc_instance_ == IntPtr.Zero || libvlc_media_player_ == IntPtr.Zero)
            {
                return;
            }
            this.SetRenderWindow((int)handle);

            IntPtr pathPtr = VLCUtil.StringToPtr(filePath);
            //从url取视频
            IntPtr libvlc_media = VLCAPI.libvlc_media_new_location(libvlc_instance_, pathPtr);

            Marshal.FreeHGlobal(pathPtr);
            if (libvlc_media != IntPtr.Zero)
            {
                //取时长前必须调用
                //VLCAPI.libvlc_media_parse(libvlc_media);


                //duration_ = VLCAPI.libvlc_media_get_duration(libvlc_media) / 1000.0;

                VLCAPI.libvlc_media_player_set_media(libvlc_media_player_, libvlc_media);

                VLCAPI.libvlc_media_release(libvlc_media);

                VLCAPI.libvlc_media_player_play(libvlc_media_player_);
            }
        }
Пример #2
0
        /// <summary>
        /// 抓图(支持多种格式)
        /// </summary>
        /// <param name="savePath">完整路径(bmp,png,jpg)</param>
        /// <param name="width">抓图宽度</param>
        /// <param name="height">抓图高度</param>
        /// <returns></returns>
        public int SnapShot(string savePath, uint width = 0, uint height = 0)
        {
            int result = -1;

            if (libvlc_media_player_ != IntPtr.Zero)
            {
                IntPtr pathPtr = VLCUtil.StringToPtr(savePath);
                result = VLCAPI.libvlc_video_take_snapshot(libvlc_media_player_, 0, pathPtr, width, height);
                Marshal.FreeHGlobal(pathPtr);
            }
            return(result);
        }
Пример #3
0
        //private double duration_;

        public VLCPlayer()
        {
            //string plugin_arg = "--plugin-path=" + System.Environment.CurrentDirectory + "\\plugins\\";
            //"--network-caching=300"减少网络延迟300秒
            // "--no-snapshot-preview"
            //"-I", "dummy", "--ignore-config", "--extraintf=logger",
            string[] args = { "--verbose=2", "--network-caching=300", "--no-snapshot-preview" };

            byte[][] argvbytes = new byte[args.Length][];

            for (int i = 0; i < args.Length; i++)
            {
                argvbytes[i] = Encoding.UTF8.GetBytes(args[i]);
            }


            libvlc_instance_ = VLCAPI.libvlc_new(args.Length, VLCUtil.ReturnIntPtr(argvbytes, args.Length));


            if (libvlc_instance_ != IntPtr.Zero)
            {
                libvlc_media_player_ = VLCAPI.libvlc_media_player_new(libvlc_instance_);
            }
        }