예제 #1
0
파일: VLCPlayer.cs 프로젝트: Joris9527/Rtmp
 /// <summary>
 /// 获取播放进度
 /// </summary>
 /// <returns></returns>
 public double GetPlayTime()
 {
     if (libvlc_media_player_ == IntPtr.Zero)
     {
         return(0);
     }
     return(VLCAPI.libvlc_media_player_get_time(libvlc_media_player_) / 1000.0);
 }
예제 #2
0
파일: VLCPlayer.cs 프로젝트: Joris9527/Rtmp
 /// <summary>
 /// 获取播放音量
 /// </summary>
 /// <returns></returns>
 public int GetVolume()
 {
     if (libvlc_media_player_ != IntPtr.Zero)
     {
         return(VLCAPI.libvlc_audio_get_volume(libvlc_media_player_));
     }
     else
     {
         return(-1);
     }
 }
예제 #3
0
파일: VLCPlayer.cs 프로젝트: Joris9527/Rtmp
        /// <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);
        }
예제 #4
0
파일: VLCPlayer.cs 프로젝트: Joris9527/Rtmp
        /// <summary>
        /// 播放
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="handle"></param>
        /// <returns> true 成功 ,false 失败</returns>
        public bool Play(string filePath, IntPtr handle)
        {
            bool flag = false;

            if (libvlc_instance_ == IntPtr.Zero || libvlc_media_player_ == IntPtr.Zero)
            {
                return(flag);
            }
            this.SetRenderWindow((int)handle);

            IntPtr pathPtr = VLCUtil.StringToPtr(filePath);

            IntPtr libvlc_media;

            if (UrlDiscern(filePath))
            {
                //从url取视频
                libvlc_media = VLCAPI.libvlc_media_new_location(libvlc_instance_, pathPtr);
            }
            else
            {
                //从本地取视频
                libvlc_media = VLCAPI.libvlc_media_new_path(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_);

                flag = true;
            }

            return(flag);
        }
예제 #5
0
파일: VLCPlayer.cs 프로젝트: Joris9527/Rtmp
        //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", "--avcodec-hw=any" };

            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_);
            }
        }
예제 #6
0
파일: VLCPlayer.cs 프로젝트: Joris9527/Rtmp
        //public double Duration()
        //{

        //    return duration_;

        //}

        public string Version()
        {
            return(VLCAPI.libvlc_get_version());
        }