Silverlight之视频录制

    

Silverlight之视频录制             

        分类:             Silverlight                   459人阅读     评论(1)     收藏     举报    

摘要:在前两篇Silverlight的文章中跟大家一块学习了Silverlight的基础知识、Silverlight摄像头麦克风的相关操作以及截图、声音录制等,在文章后面也简单的说明了为什么没有视频录制,今天就和大家一块看一下上一节中最后的一个问题:如何使用Silverlight进行视频录制。

主要内容:

1.NESL项目简介

2.使用NESL实现视频录制

3.注意

一、NESL项目简介

在silverlight 中如何录制视频?相信这个问题有不少朋友都搜索过,但是好像目前还没有见到很好的答案,究其原因其实就是视频编码问题。当然也有朋友提到直接进行截图,只要每秒截取足够多的图片,然后依次播放就可以形成视频。但是我看到国外一个朋友使用此方法进行了几十秒的视频录制,其文件大小就达到了百兆级别,而且还进行了优化。因此这种方式要实现视频录制就目前而言还不是很合适。那么到底有没有好的方法呢?答案是有,但有限制,那就是借助于NESL。

Native Extensions for Silverlight(简称NESL)是由微软Silverlight团队进行开发,其目的主要为了增强Silverlight Out-of-Browser离线应用的功能。大家都知道虽然Silverlight 4的OOB应用支持信任人权限提升功能,允许Silverlight的OOB应用对COM组件的访问,但对绝大多数Windows API仍旧无法调用,而NESL的出现正是为了解决这个问题。在最新的NESL 2.0中包含了大量有用的功能,而这其中就包括今天要说的视频编码部分。在NESL中有一个类库Microsoft.Silverlight.Windows.LocalEncode.dll主要负责本地视频和音频编码,这里就是用此类库来解决上面提到的视频录制问题。

二、使用NESL实现视频录制

在Microsoft.Silverlight.Windows.LocalEncode.dll中一个核心类就是EncodeSession,它负责音频和视频的编码输出工作。使用EncodeSession进行视频录制大概分为下面两步:

1.准备输入输出信息

在这个过程中需要定义VideInputFormatInfo、AudioInputFormatInfo、VideoOutputFormatInfo、AudioOutputFormatInfo和OutputContainerInfo,然后调用EncodeSession.Prepare()方法。

2.捕获视频输出

当输入输出信息准备好之后接下来就是调用EncodeSession.Start()方法进行视频编码输出。当然为了接收音频和视频数据必须准备两个sink类,分别继承于AudioSink和VideoSink,在这两个sink中指定CaptureSource,并且在对应的OnSample中调用EncodeSession的WirteVideoSample()和WirteAudioSample()接收并编码数据(关于AudioSink在前面的文章中已经说过,VideoSink与之类似)。

知道了EncodeSession的使用方法后下面就将其操作进行简单封装,LocalCamera.cs是本例中的核心类:

  1. using System;  
  2. using System.Collections.ObjectModel;  
  3. using System.IO;  
  4. using System.Windows;  
  5. using System.Windows.Threading;  
  6. using System.Windows.Media;  
  7. using System.Windows.Controls;  
  8. using System.Windows.Shapes;  
  9. using Microsoft.Silverlight.Windows.LocalEncode;  
  10.   
  11. namespace Cmj.MyWeb.MySilverlight.SilverlightMeida  
  12. {  
  13.     /// <summary>  
  14.     /// 编码状态  
  15.     /// </summary>  
  16.     public enum EncodeSessionState  
  17.     {  
  18.         Start,  
  19.         Pause,  
  20.         Stop  
  21.     }  
  22.     /// <summary>  
  23.     /// 本地视频对象  
  24.     /// </summary>  
  25.     public class LocalCamera  
  26.     {  
  27.         private string _saveFullPath = "";  
  28.         private uint _videoWidth = 640;  
  29.         private uint _videoHeight = 480;  
  30.         private VideoSinkExtensions _videoSink = null;  
  31.         private AudioSinkExtensions _audioSink= null;  
  32.         private EncodeSession _encodeSession = null;  
  33.         private UserControl _page = null;  
  34.         private CaptureSource _cSource = null;  
  35.         public LocalCamera(UserControl page,VideoFormat videoFormat,AudioFormat audioFormat)  
  36.         {  
  37.             //this._saveFullPath = saveFullPath;  
  38.             this._videoWidth = (uint)videoFormat.PixelWidth;  
  39.             this._videoHeight = (uint)videoFormat.PixelHeight;  
  40.             this._page = page;  
  41.             this.SessionState = EncodeSessionState.Stop;  
  42.             //this._encodeSession = new EncodeSession();  
  43.             _cSource = new CaptureSource();  
  44.             this.VideoDevice = DefaultVideoDevice;  
  45.             this.VideoDevice.DesiredFormat = videoFormat;  
  46.             this.AudioDevice = DefaultAudioDevice;  
  47.             this.AudioDevice.DesiredFormat = audioFormat;  
  48.             _cSource.VideoCaptureDevice = this.VideoDevice;  
  49.             _cSource.AudioCaptureDevice = this.AudioDevice;  
  50.             audioInputFormatInfo = new AudioInputFormatInfo() { SourceCompressionType = FormatConstants.AudioFormat_PCM };  
  51.             videoInputFormatInfo = new VideoInputFormatInfo() { SourceCompressionType = FormatConstants.VideoFormat_ARGB32 };  
  52.             audioOutputFormatInfo = new AudioOutputFormatInfo() { TargetCompressionType = FormatConstants.AudioFormat_AAC };  
  53.             videoOutputFormatInfo = new VideoOutputFormatInfo() { TargetCompressionType = FormatConstants.VideoFormat_H264 };  
  54.             outputContainerInfo = new OutputContainerInfo() { ContainerType = FormatConstants.TranscodeContainerType_MPEG4 };  
  55.         }  
  56.   
  57.         public LocalCamera(UserControl page,VideoCaptureDevice videoCaptureDevice,AudioCaptureDevice audioCaptureDevice, VideoFormat videoFormat, AudioFormat audioFormat)  
  58.         {  
  59.             //this._saveFullPath = saveFullPath;  
  60.             this._videoWidth = (uint)videoFormat.PixelWidth;  
  61.             this._videoHeight = (uint)videoFormat.PixelHeight;  
  62.             this._page = page;  
  63.             this.SessionState = EncodeSessionState.Stop;  
  64.             //this._encodeSession = new EncodeSession();  
  65.             _cSource = new CaptureSource();  
  66.             this.VideoDevice = videoCaptureDevice;  
  67.             this.VideoDevice.DesiredFormat = videoFormat;  
  68.             this.AudioDevice = audioCaptureDevice;  
  69.             this.AudioDevice.DesiredFormat = audioFormat;  
  70.             _cSource.VideoCaptureDevice = this.VideoDevice;  
  71.             _cSource.AudioCaptureDevice = this.AudioDevice;  
  72.             audioInputFormatInfo = new AudioInputFormatInfo() { SourceCompressionType = FormatConstants.AudioFormat_PCM };  
  73.             videoInputFormatInfo = new VideoInputFormatInfo() { SourceCompressionType = FormatConstants.VideoFormat_ARGB32 };  
  74.             audioOutputFormatInfo = new AudioOutputFormatInfo() { TargetCompressionType = FormatConstants.AudioFormat_AAC };  
  75.             videoOutputFormatInfo = new VideoOutputFormatInfo() { TargetCompressionType = FormatConstants.VideoFormat_H264 };  
  76.             outputContainerInfo = new OutputContainerInfo() { ContainerType = FormatConstants.TranscodeContainerType_MPEG4 };  
  77.         }  
  78.   
  79.         public EncodeSessionState SessionState   
  80.         {  
  81.             get;  
  82.             set;  
  83.         }  
  84.         public EncodeSession Session  
  85.         {  
  86.             get  
  87.             {  
  88.                 return _encodeSession;  
  89.             }  
  90.             set  
  91.             {  
  92.                 _encodeSession = value;  
  93.             }  
  94.         }  
  95.         /// <summary>  
  96.         /// 编码对象所在用户控件对象  
  97.         /// </summary>  
  98.         public UserControl OwnPage  
  99.         {  
  100.             get  
  101.             {  
  102.                 return _page;  
  103.             }  
  104.             set  
  105.             {  
  106.                 _page = value;  
  107.             }  
  108.         }  
  109.         /// <summary>  
  110.         /// 捕获源  
  111.         /// </summary>  
  112.         public CaptureSource Source  
  113.         {  
  114.             get  
  115.             {  
  116.                 return _cSource;  
  117.             }  
  118.         }  
  119.         /// <summary>  
  120.         /// 操作音频对象  
  121.         /// </summary>  
  122.         public AudioSinkExtensions AudioSink  
  123.         {  
  124.             get  
  125.             {  
  126.                 return _audioSink;  
  127.             }  
  128.         }  
  129.   
  130.         public static VideoCaptureDevice DefaultVideoDevice  
  131.         {  
  132.             get  
  133.             {  
  134.                 return CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();  
  135.             }  
  136.         }  
  137.           
  138.         public static ReadOnlyCollection<VideoCaptureDevice> AvailableVideoDevice  
  139.         {  
  140.             get  
  141.             {  
  142.                 return CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices();  
  143.             }  
  144.         }  
  145.   
  146.         public VideoCaptureDevice VideoDevice  
  147.         {  
  148.             get;  
  149.             set;  
  150.         }  
  151.   
  152.         public static AudioCaptureDevice DefaultAudioDevice  
  153.         {  
  154.             get  
  155.             {  
  156.                 return CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice();  
  157.             }  
  158.         }  
  159.         public static ReadOnlyCollection<AudioCaptureDevice> AvailableAudioDevice  
  160.         {  
  161.             get  
  162.             {  
  163.                 return CaptureDeviceConfiguration.GetAvailableAudioCaptureDevices();  
  164.             }  
  165.         }  
  166.   
  167.         public AudioCaptureDevice AudioDevice  
  168.         {  
  169.             get;  
  170.             set;  
  171.         }  
  172.   
  173.         private Object lockObj = new object();  
  174.         internal VideoInputFormatInfo videoInputFormatInfo;  
  175.         internal AudioInputFormatInfo audioInputFormatInfo;  
  176.         internal VideoOutputFormatInfo videoOutputFormatInfo;  
  177.         internal AudioOutputFormatInfo audioOutputFormatInfo;  
  178.         internal OutputContainerInfo outputContainerInfo;  
  179.         /// <summary>  
  180.         /// 视频录制  
  181.         /// </summary>  
  182.         public void StartRecord()  
  183.         {  
  184.             lock (lockObj)  
  185.             {  
  186.                 if (this.SessionState == EncodeSessionState.Stop)  
  187.                 {  
  188.                     _videoSink = new VideoSinkExtensions(this);  
  189.                     _audioSink = new AudioSinkExtensions(this);  
  190.                     //_audioSink.VolumnChange += new AudioSinkExtensions.VolumnChangeHanlder(_audioSink_VolumnChange);  
  191.                     if (_encodeSession == null)  
  192.                     {  
  193.                         _encodeSession = new EncodeSession();  
  194.                     }  
  195.                     PrepareFormatInfo(_cSource.VideoCaptureDevice.DesiredFormat, _cSource.AudioCaptureDevice.DesiredFormat);  
  196.                     _encodeSession.Prepare(videoInputFormatInfo, audioInputFormatInfo, videoOutputFormatInfo, audioOutputFormatInfo, outputContainerInfo);  
  197.                     _encodeSession.Start(false, 200);  
  198.                     this.SessionState = EncodeSessionState.Start;  
  199.                 }  
  200.             }  
  201.         }  
  202.         /// <summary>  
  203.         /// 音量大小指示  
  204.         /// </summary>  
  205.         /// <param name="sender"></param>  
  206.         /// <param name="e"></param>  
  207.         //void _audioSink_VolumnChange(object sender, VolumnChangeArgs e)  
  208.         //{  
  209.         //    this.OwnPage.Dispatcher.BeginInvoke(new Action(() =>  
  210.         //    {  
  211.         //        (  
  212.         //            this.OwnPage.Tag as ProgressBar).Value = e.Volumn;  
  213.         //    }));  
  214.         //}  
  215.   
  216.         /// <summary>  
  217.         /// 暂停录制  
  218.         /// </summary>  
  219.         public void PauseRecord()  
  220.         {  
  221.             lock (lockObj)  
  222.             {  
  223.                 this.SessionState = EncodeSessionState.Pause;  
  224.                 _encodeSession.Pause();  
  225.             }  
  226.         }  
  227.         /// <summary>  
  228.         /// 停止录制  
  229.         /// </summary>  
  230.         public void StopRecord()  
  231.         {  
  232.             lock (lockObj)  
  233.             {  
  234.                 this.SessionState = EncodeSessionState.Stop;  
  235.                 _encodeSession.Shutdown();  
  236.                 _videoSink = null;  
  237.                 _audioSink = null;  
  238.             }  
  239.         }  
  240.   
  241.         /// <summary>  
  242.         /// 准备编码信息  
  243.         /// </summary>  
  244.         /// <param name="videoFormat"></param>  
  245.         /// <param name="audioFormat"></param>  
  246.         private void PrepareFormatInfo(VideoFormat videoFormat, AudioFormat audioFormat)  
  247.         {  
  248.             uint FrameRateRatioNumerator = 0;  
  249.             uint FrameRateRationDenominator = 0;  
  250.             FormatConstants.FrameRateToRatio((float)Math.Round(videoFormat.FramesPerSecond, 2), ref FrameRateRatioNumerator, ref FrameRateRationDenominator);  
  251.   
  252.             videoInputFormatInfo.FrameRateRatioNumerator = FrameRateRatioNumerator;  
  253.             videoInputFormatInfo.FrameRateRatioDenominator = FrameRateRationDenominator;  
  254.             videoInputFormatInfo.FrameWidthInPixels = _videoWidth;  
  255.             videoInputFormatInfo.FrameHeightInPixels = _videoHeight ;  
  256.             videoInputFormatInfo.Stride = (int)_videoWidth*-4;  
  257.   
  258.             videoOutputFormatInfo.FrameRateRatioNumerator = FrameRateRatioNumerator;  
  259.             videoOutputFormatInfo.FrameRateRatioDenominator = FrameRateRationDenominator;  
  260.             videoOutputFormatInfo.FrameWidthInPixels = videoOutputFormatInfo.FrameWidthInPixels == 0 ? (uint)videoFormat.PixelWidth : videoOutputFormatInfo.FrameWidthInPixels;  
  261.             videoOutputFormatInfo.FrameHeightInPixels = videoOutputFormatInfo.FrameHeightInPixels == 0 ? (uint)videoFormat.PixelHeight : videoOutputFormatInfo.FrameHeightInPixels;  
  262.   
  263.             audioInputFormatInfo.BitsPerSample = (uint)audioFormat.BitsPerSample;  
  264.             audioInputFormatInfo.SamplesPerSecond = (uint)audioFormat.SamplesPerSecond;  
  265.             audioInputFormatInfo.ChannelCount = (uint)audioFormat.Channels;  
  266.             if (outputContainerInfo.FilePath == null || outputContainerInfo.FilePath == string.Empty)  
  267.             {  
  268.                 _saveFullPath=System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), "cCameraRecordVideo.tmp");  
  269.             }  
  270.             outputContainerInfo.FilePath = _saveFullPath;  
  271.             //outputContainerInfo.FilePath = _saveFullPath;  
  272.             if (audioOutputFormatInfo.AverageBitrate == 0)  
  273.                 audioOutputFormatInfo.AverageBitrate = 24000;  
  274.             if (videoOutputFormatInfo.AverageBitrate == 0)  
  275.                 videoOutputFormatInfo.AverageBitrate = 2000000;  
  276.         }  
  277.   
  278.         /// <summary>  
  279.         /// 开始捕获  
  280.         /// </summary>  
  281.         public void StartCaptrue()  
  282.         {  
  283.             if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess())  
  284.             {  
  285.                 _cSource.Start();  
  286.             }  
  287.         }  
  288.   
  289.         /// <summary>  
  290.         /// 停止捕获  
  291.         /// </summary>  
  292.         public void StopCapture()  
  293.         {  
  294.             _videoSink = null;  
  295.             _audioSink = null;  
  296.             _cSource.Stop();  
  297.         }  
  298.   
  299.         /// <summary>  
  300.         /// 获得视频  
  301.         /// </summary>  
  302.         /// <returns></returns>  
  303.         public VideoBrush GetVideoBrush()  
  304.         {  
  305.             VideoBrush vBrush = new VideoBrush();  
  306.             vBrush.SetSource(_cSource);  
  307.             return vBrush;  
  308.         }  
  309.   
  310.         /// <summary>  
  311.         /// 获得视频  
  312.         /// </summary>  
  313.         /// <returns></returns>  
  314.         public Rectangle GetVideoRectangle()  
  315.         {  
  316.             Rectangle rctg = new Rectangle();  
  317.             rctg.Width = this._videoWidth;  
  318.             rctg.Height = this._videoHeight;  
  319.             rctg.Fill = GetVideoBrush();  
  320.             return rctg;  
  321.         }  
  322.   
  323.         /// <summary>  
  324.         /// 保存视频  
  325.         /// </summary>  
  326.         public void SaveRecord()  
  327.         {  
  328.             if (_saveFullPath == string.Empty)  
  329.             {  
  330.                 MessageBox.Show("尚未录制视频,无法进行保存!""系统提示", MessageBoxButton.OK);  
  331.                 return;  
  332.             }  
  333.             SaveFileDialog sfd = new SaveFileDialog  
  334.             {  
  335.                 Filter = "MP4 Files (*.mp4)|*.mp4",  
  336.                 DefaultExt = ".mp4",  
  337.                 FilterIndex = 1  
  338.             };  
  339.   
  340.             if ((bool)sfd.ShowDialog())  
  341.             {  
  342.                 using (Stream stm=sfd.OpenFile())  
  343.                 {  
  344.                     FileStream fs = new FileStream(_saveFullPath, FileMode.Open, FileAccess.Read);  
  345.                     try  
  346.                     {  
  347.                         byte[] buffur = new byte[fs.Length];  
  348.                         fs.Read(buffur, 0, (int)fs.Length);  
  349.                         stm.Write(buffur, 0, (int)buffur.Length);  
  350.                         fs.Close();  
  351.                         File.Delete(_saveFullPath);  
  352.                     }  
  353.                     catch (IOException ioe)  
  354.                     {  
  355.                         MessageBox.Show("文件保存失败!错误信息如下:"+Environment.NewLine+ioe.Message,"系统提示",MessageBoxButton.OK);  
  356.                     }  
  357.                     stm.Close();  
  358.                 }  
  359.             }  
  360.         }  
  361.     }  
  362. }  
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Windows;
using System.Windows.Threading;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows.Shapes;
using Microsoft.Silverlight.Windows.LocalEncode;

namespace Cmj.MyWeb.MySilverlight.SilverlightMeida
{
    /// <summary>
    /// 编码状态
    /// </summary>
    public enum EncodeSessionState
    {
        Start,
        Pause,
        Stop
    }
    /// <summary>
    /// 本地视频对象
    /// </summary>
    public class LocalCamera
    {
        private string _saveFullPath = "";
        private uint _videoWidth = 640;
        private uint _videoHeight = 480;
        private VideoSinkExtensions _videoSink = null;
        private AudioSinkExtensions _audioSink= null;
        private EncodeSession _encodeSession = null;
        private UserControl _page = null;
        private CaptureSource _cSource = null;
        public LocalCamera(UserControl page,VideoFormat videoFormat,AudioFormat audioFormat)
        {
            //this._saveFullPath = saveFullPath;
            this._videoWidth = (uint)videoFormat.PixelWidth;
            this._videoHeight = (uint)videoFormat.PixelHeight;
            this._page = page;
            this.SessionState = EncodeSessionState.Stop;
            //this._encodeSession = new EncodeSession();
            _cSource = new CaptureSource();
            this.VideoDevice = DefaultVideoDevice;
            this.VideoDevice.DesiredFormat = videoFormat;
            this.AudioDevice = DefaultAudioDevice;
            this.AudioDevice.DesiredFormat = audioFormat;
            _cSource.VideoCaptureDevice = this.VideoDevice;
            _cSource.AudioCaptureDevice = this.AudioDevice;
            audioInputFormatInfo = new AudioInputFormatInfo() { SourceCompressionType = FormatConstants.AudioFormat_PCM };
            videoInputFormatInfo = new VideoInputFormatInfo() { SourceCompressionType = FormatConstants.VideoFormat_ARGB32 };
            audioOutputFormatInfo = new AudioOutputFormatInfo() { TargetCompressionType = FormatConstants.AudioFormat_AAC };
            videoOutputFormatInfo = new VideoOutputFormatInfo() { TargetCompressionType = FormatConstants.VideoFormat_H264 };
            outputContainerInfo = new OutputContainerInfo() { ContainerType = FormatConstants.TranscodeContainerType_MPEG4 };
        }

        public LocalCamera(UserControl page,VideoCaptureDevice videoCaptureDevice,AudioCaptureDevice audioCaptureDevice, VideoFormat videoFormat, AudioFormat audioFormat)
        {
            //this._saveFullPath = saveFullPath;
            this._videoWidth = (uint)videoFormat.PixelWidth;
            this._videoHeight = (uint)videoFormat.PixelHeight;
            this._page = page;
            this.SessionState = EncodeSessionState.Stop;
            //this._encodeSession = new EncodeSession();
            _cSource = new CaptureSource();
            this.VideoDevice = videoCaptureDevice;
            this.VideoDevice.DesiredFormat = videoFormat;
            this.AudioDevice = audioCaptureDevice;
            this.AudioDevice.DesiredFormat = audioFormat;
            _cSource.VideoCaptureDevice = this.VideoDevice;
            _cSource.AudioCaptureDevice = this.AudioDevice;
            audioInputFormatInfo = new AudioInputFormatInfo() { SourceCompressionType = FormatConstants.AudioFormat_PCM };
            videoInputFormatInfo = new VideoInputFormatInfo() { SourceCompressionType = FormatConstants.VideoFormat_ARGB32 };
            audioOutputFormatInfo = new AudioOutputFormatInfo() { TargetCompressionType = FormatConstants.AudioFormat_AAC };
            videoOutputFormatInfo = new VideoOutputFormatInfo() { TargetCompressionType = FormatConstants.VideoFormat_H264 };
            outputContainerInfo = new OutputContainerInfo() { ContainerType = FormatConstants.TranscodeContainerType_MPEG4 };
        }

        public EncodeSessionState SessionState 
        {
            get;
            set;
        }
        public EncodeSession Session
        {
            get
            {
                return _encodeSession;
            }
            set
            {
                _encodeSession = value;
            }
        }
        /// <summary>
        /// 编码对象所在用户控件对象
        /// </summary>
        public UserControl OwnPage
        {
            get
            {
                return _page;
            }
            set
            {
                _page = value;
            }
        }
        /// <summary>
        /// 捕获源
        /// </summary>
        public CaptureSource Source
        {
            get
            {
                return _cSource;
            }
        }
        /// <summary>
        /// 操作音频对象
        /// </summary>
        public AudioSinkExtensions AudioSink
        {
            get
            {
                return _audioSink;
            }
        }

        public static VideoCaptureDevice DefaultVideoDevice
        {
            get
            {
                return CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
            }
        }
        
        public static ReadOnlyCollection<VideoCaptureDevice> AvailableVideoDevice
        {
            get
            {
                return CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices();
            }
        }

        public VideoCaptureDevice VideoDevice
        {
            get;
            set;
        }

        public static AudioCaptureDevice DefaultAudioDevice
        {
            get
            {
                return CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice();
            }
        }
        public static ReadOnlyCollection<AudioCaptureDevice> AvailableAudioDevice
        {
            get
            {
                return CaptureDeviceConfiguration.GetAvailableAudioCaptureDevices();
            }
        }

        public AudioCaptureDevice AudioDevice
        {
            get;
            set;
        }

        private Object lockObj = new object();
        internal VideoInputFormatInfo videoInputFormatInfo;
        internal AudioInputFormatInfo audioInputFormatInfo;
        internal VideoOutputFormatInfo videoOutputFormatInfo;
        internal AudioOutputFormatInfo audioOutputFormatInfo;
        internal OutputContainerInfo outputContainerInfo;
        /// <summary>
        /// 视频录制
        /// </summary>
        public void StartRecord()
        {
            lock (lockObj)
            {
                if (this.SessionState == EncodeSessionState.Stop)
                {
                    _videoSink = new VideoSinkExtensions(this);
                    _audioSink = new AudioSinkExtensions(this);
                    //_audioSink.VolumnChange += new AudioSinkExtensions.VolumnChangeHanlder(_audioSink_VolumnChange);
                    if (_encodeSession == null)
                    {
                        _encodeSession = new EncodeSession();
                    }
                    PrepareFormatInfo(_cSource.VideoCaptureDevice.DesiredFormat, _cSource.AudioCaptureDevice.DesiredFormat);
                    _encodeSession.Prepare(videoInputFormatInfo, audioInputFormatInfo, videoOutputFormatInfo, audioOutputFormatInfo, outputContainerInfo);
                    _encodeSession.Start(false, 200);
                    this.SessionState = EncodeSessionState.Start;
                }
            }
        }
        /// <summary>
        /// 音量大小指示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //void _audioSink_VolumnChange(object sender, VolumnChangeArgs e)
        //{
        //    this.OwnPage.Dispatcher.BeginInvoke(new Action(() =>
        //    {
        //        (
        //            this.OwnPage.Tag as ProgressBar).Value = e.Volumn;
        //    }));
        //}

        /// <summary>
        /// 暂停录制
        /// </summary>
        public void PauseRecord()
        {
            lock (lockObj)
            {
                this.SessionState = EncodeSessionState.Pause;
                _encodeSession.Pause();
            }
        }
        /// <summary>
        /// 停止录制
        /// </summary>
        public void StopRecord()
        {
            lock (lockObj)
            {
                this.SessionState = EncodeSessionState.Stop;
                _encodeSession.Shutdown();
                _videoSink = null;
                _audioSink = null;
            }
        }

        /// <summary>
        /// 准备编码信息
        /// </summary>
        /// <param name="videoFormat"></param>
        /// <param name="audioFormat"></param>
        private void PrepareFormatInfo(VideoFormat videoFormat, AudioFormat audioFormat)
        {
            uint FrameRateRatioNumerator = 0;
            uint FrameRateRationDenominator = 0;
            FormatConstants.FrameRateToRatio((float)Math.Round(videoFormat.FramesPerSecond, 2), ref FrameRateRatioNumerator, ref FrameRateRationDenominator);

            videoInputFormatInfo.FrameRateRatioNumerator = FrameRateRatioNumerator;
            videoInputFormatInfo.FrameRateRatioDenominator = FrameRateRationDenominator;
            videoInputFormatInfo.FrameWidthInPixels = _videoWidth;
            videoInputFormatInfo.FrameHeightInPixels = _videoHeight ;
            videoInputFormatInfo.Stride = (int)_videoWidth*-4;

            videoOutputFormatInfo.FrameRateRatioNumerator = FrameRateRatioNumerator;
            videoOutputFormatInfo.FrameRateRatioDenominator = FrameRateRationDenominator;
            videoOutputFormatInfo.FrameWidthInPixels = videoOutputFormatInfo.FrameWidthInPixels == 0 ? (uint)videoFormat.PixelWidth : videoOutputFormatInfo.FrameWidthInPixels;
            videoOutputFormatInfo.FrameHeightInPixels = videoOutputFormatInfo.FrameHeightInPixels == 0 ? (uint)videoFormat.PixelHeight : videoOutputFormatInfo.FrameHeightInPixels;

            audioInputFormatInfo.BitsPerSample = (uint)audioFormat.BitsPerSample;
            audioInputFormatInfo.SamplesPerSecond = (uint)audioFormat.SamplesPerSecond;
            audioInputFormatInfo.ChannelCount = (uint)audioFormat.Channels;
            if (outputContainerInfo.FilePath == null || outputContainerInfo.FilePath == string.Empty)
            {
                _saveFullPath=System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), "cCameraRecordVideo.tmp");
            }
            outputContainerInfo.FilePath = _saveFullPath;
            //outputContainerInfo.FilePath = _saveFullPath;
            if (audioOutputFormatInfo.AverageBitrate == 0)
                audioOutputFormatInfo.AverageBitrate = 24000;
            if (videoOutputFormatInfo.AverageBitrate == 0)
                videoOutputFormatInfo.AverageBitrate = 2000000;
        }

        /// <summary>
        /// 开始捕获
        /// </summary>
        public void StartCaptrue()
        {
            if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess())
            {
                _cSource.Start();
            }
        }

        /// <summary>
        /// 停止捕获
        /// </summary>
        public void StopCapture()
        {
            _videoSink = null;
            _audioSink = null;
            _cSource.Stop();
        }

        /// <summary>
        /// 获得视频
        /// </summary>
        /// <returns></returns>
        public VideoBrush GetVideoBrush()
        {
            VideoBrush vBrush = new VideoBrush();
            vBrush.SetSource(_cSource);
            return vBrush;
        }

        /// <summary>
        /// 获得视频
        /// </summary>
        /// <returns></returns>
        public Rectangle GetVideoRectangle()
        {
            Rectangle rctg = new Rectangle();
            rctg.Width = this._videoWidth;
            rctg.Height = this._videoHeight;
            rctg.Fill = GetVideoBrush();
            return rctg;
        }

        /// <summary>
        /// 保存视频
        /// </summary>
        public void SaveRecord()
        {
            if (_saveFullPath == string.Empty)
            {
                MessageBox.Show("尚未录制视频,无法进行保存!", "系统提示", MessageBoxButton.OK);
                return;
            }
            SaveFileDialog sfd = new SaveFileDialog
            {
                Filter = "MP4 Files (*.mp4)|*.mp4",
                DefaultExt = ".mp4",
                FilterIndex = 1
            };

            if ((bool)sfd.ShowDialog())
            {
                using (Stream stm=sfd.OpenFile())
                {
                    FileStream fs = new FileStream(_saveFullPath, FileMode.Open, FileAccess.Read);
                    try
                    {
                        byte[] buffur = new byte[fs.Length];
                        fs.Read(buffur, 0, (int)fs.Length);
                        stm.Write(buffur, 0, (int)buffur.Length);
                        fs.Close();
                        File.Delete(_saveFullPath);
                    }
                    catch (IOException ioe)
                    {
                        MessageBox.Show("文件保存失败!错误信息如下:"+Environment.NewLine+ioe.Message,"系统提示",MessageBoxButton.OK);
                    }
                    stm.Close();
                }
            }
        }
    }
}

当然上面说过必须有两个Sink:

  1. using System;  
  2. using System.Windows.Media;  
  3. using System.Windows.Controls;  
  4. using Microsoft.Silverlight.Windows.LocalEncode;  
  5.   
  6. namespace Cmj.MyWeb.MySilverlight.SilverlightMeida  
  7. {  
  8.     public class VideoSinkExtensions:VideoSink  
  9.     {  
  10.         //private UserControl _page;  
  11.         //private EncodeSession _session;  
  12.         private LocalCamera _localCamera;  
  13.         public VideoSinkExtensions(LocalCamera localCamera)  
  14.         {  
  15.             //this._page = page;  
  16.             this._localCamera = localCamera;  
  17.             //this._session = session;  
  18.             this.CaptureSource = _localCamera.Source;  
  19.         }  
  20.   
  21.         protected override void OnCaptureStarted()  
  22.         {  
  23.               
  24.         }  
  25.   
  26.         protected override void OnCaptureStopped()  
  27.         {  
  28.   
  29.         }  
  30.   
  31.         protected override void OnFormatChange(VideoFormat videoFormat)  
  32.         {  
  33.   
  34.         }  
  35.   
  36.         protected override void OnSample(long sampleTimeInHundredNanoseconds, long frameDurationInHundredNanoseconds, byte[] sampleData)  
  37.         {  
  38.             if (_localCamera.SessionState == EncodeSessionState.Start)  
  39.             {  
  40.                 _localCamera.OwnPage.Dispatcher.BeginInvoke(new Action<longlongbyte[]>((ts, dur, data) =>  
  41.                 {  
  42.                     _localCamera.Session.WriteVideoSample(data, data.Length, ts, dur);  
  43.                 }), sampleTimeInHundredNanoseconds, frameDurationInHundredNanoseconds, sampleData);  
  44.             }  
  45.         }  
  46.     }  
  47. }  
using System;
using System.Windows.Media;
using System.Windows.Controls;
using Microsoft.Silverlight.Windows.LocalEncode;

namespace Cmj.MyWeb.MySilverlight.SilverlightMeida
{
    public class VideoSinkExtensions:VideoSink
    {
        //private UserControl _page;
        //private EncodeSession _session;
        private LocalCamera _localCamera;
        public VideoSinkExtensions(LocalCamera localCamera)
        {
            //this._page = page;
            this._localCamera = localCamera;
            //this._session = session;
            this.CaptureSource = _localCamera.Source;
        }

        protected override void OnCaptureStarted()
        {
            
        }

        protected override void OnCaptureStopped()
        {

        }

        protected override void OnFormatChange(VideoFormat videoFormat)
        {

        }

        protected override void OnSample(long sampleTimeInHundredNanoseconds, long frameDurationInHundredNanoseconds, byte[] sampleData)
        {
            if (_localCamera.SessionState == EncodeSessionState.Start)
            {
                _localCamera.OwnPage.Dispatcher.BeginInvoke(new Action<long, long, byte[]>((ts, dur, data) =>
                {
                    _localCamera.Session.WriteVideoSample(data, data.Length, ts, dur);
                }), sampleTimeInHundredNanoseconds, frameDurationInHundredNanoseconds, sampleData);
            }
        }
    }
}
  1. using System;  
  2. using System.Windows.Media;  
  3. using System.Windows.Controls;  
  4. using Microsoft.Silverlight.Windows.LocalEncode;  
  5.   
  6.   
  7. namespace Cmj.MyWeb.MySilverlight.SilverlightMeida  
  8. {  
  9.     public class AudioSinkExtensions:AudioSink  
  10.     {  
  11.         private LocalCamera _localCamera;  
  12.         public AudioSinkExtensions(LocalCamera localCamera)  
  13.         {  
  14.             this._localCamera = localCamera;  
  15.             this.CaptureSource = _localCamera.Source;  
  16.   
  17.         }  
  18.         protected override void OnCaptureStarted()  
  19.         {  
  20.               
  21.         }  
  22.   
  23.         protected override void OnCaptureStopped()  
  24.         {  
  25.   
  26.         }  
  27.   
  28.         protected override void OnFormatChange(AudioFormat audioFormat)  
  29.         {  
  30.   
  31.         }  
  32.   
  33.         protected override void OnSamples(long sampleTimeInHundredNanoseconds, long sampleDurationInHundredNanoseconds, byte[] sampleData)  
  34.         {  
  35.             if (_localCamera.SessionState == EncodeSessionState.Start)  
  36.             {  
  37.                 _localCamera.OwnPage.Dispatcher.BeginInvoke(new Action<longlongbyte[]>((ts, dur, data) =>  
  38.                 {  
  39.                     _localCamera.Session.WriteAudioSample(data, data.Length, ts, dur);  
  40.                 }), sampleTimeInHundredNanoseconds, sampleDurationInHundredNanoseconds, sampleData);  
  41.   
  42.                 //计算音量变化  
  43.                 //for (int index = 0; index < sampleData.Length; index += 1)  
  44.                 //{  
  45.                 //    short sample = (short)((sampleData[index] << 8) | sampleData[index]);  
  46.                 //    float sample32 = sample / 32768f;  
  47.                 //    float maxValue = 0;  
  48.                 //    float minValue = 0;  
  49.                 //    maxValue = Math.Max(maxValue, sample32);  
  50.                 //    minValue = Math.Min(minValue, sample32);  
  51.                 //    float lastPeak = Math.Max(maxValue, Math.Abs(minValue));  
  52.                 //    float micLevel = (100 - (lastPeak * 100)) * 10;  
  53.                 //    OnVolumnChange(this, new VolumnChangeArgs() { Volumn=micLevel});  
  54.                 //}  
  55.             }  
  56.         }  
  57.   
  58.   
  59.         /// <summary>  
  60.         /// 定义一个事件,反馈音量变化  
  61.         /// </summary>  
  62.         /// <param name="sender"></param>  
  63.         /// <param name="e"></param>  
  64.         //public delegate void VolumnChangeHanlder(object sender, VolumnChangeArgs e);  
  65.         //public event VolumnChangeHanlder VolumnChange;  
  66.         //private void OnVolumnChange(object sender, VolumnChangeArgs e)  
  67.         //{  
  68.         //    if (VolumnChange != null)  
  69.         //    {  
  70.         //        VolumnChange(sender, e);  
  71.         //    }  
  72.         //}  
  73.     }  
  74.   
  75.     //public class VolumnChangeArgs : EventArgs  
  76.     //{  
  77.     //    public float Volumn  
  78.     //    {  
  79.     //        get;  
  80.     //        internal set;  
  81.     //    }  
  82.     //}  
  83. }  
using System;
using System.Windows.Media;
using System.Windows.Controls;
using Microsoft.Silverlight.Windows.LocalEncode;


namespace Cmj.MyWeb.MySilverlight.SilverlightMeida
{
    public class AudioSinkExtensions:AudioSink
    {
        private LocalCamera _localCamera;
        public AudioSinkExtensions(LocalCamera localCamera)
        {
            this._localCamera = localCamera;
            this.CaptureSource = _localCamera.Source;

        }
        protected override void OnCaptureStarted()
        {
            
        }

        protected override void OnCaptureStopped()
        {

        }

        protected override void OnFormatChange(AudioFormat audioFormat)
        {

        }

        protected override void OnSamples(long sampleTimeInHundredNanoseconds, long sampleDurationInHundredNanoseconds, byte[] sampleData)
        {
            if (_localCamera.SessionState == EncodeSessionState.Start)
            {
                _localCamera.OwnPage.Dispatcher.BeginInvoke(new Action<long, long, byte[]>((ts, dur, data) =>
                {
                    _localCamera.Session.WriteAudioSample(data, data.Length, ts, dur);
                }), sampleTimeInHundredNanoseconds, sampleDurationInHundredNanoseconds, sampleData);

                //计算音量变化
                //for (int index = 0; index < sampleData.Length; index += 1)
                //{
                //    short sample = (short)((sampleData[index] << 8) | sampleData[index]);
                //    float sample32 = sample / 32768f;
                //    float maxValue = 0;
                //    float minValue = 0;
                //    maxValue = Math.Max(maxValue, sample32);
                //    minValue = Math.Min(minValue, sample32);
                //    float lastPeak = Math.Max(maxValue, Math.Abs(minValue));
                //    float micLevel = (100 - (lastPeak * 100)) * 10;
                //    OnVolumnChange(this, new VolumnChangeArgs() { Volumn=micLevel});
                //}
            }
        }


        /// <summary>
        /// 定义一个事件,反馈音量变化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //public delegate void VolumnChangeHanlder(object sender, VolumnChangeArgs e);
        //public event VolumnChangeHanlder VolumnChange;
        //private void OnVolumnChange(object sender, VolumnChangeArgs e)
        //{
        //    if (VolumnChange != null)
        //    {
        //        VolumnChange(sender, e);
        //    }
        //}
    }

    //public class VolumnChangeArgs : EventArgs
    //{
    //    public float Volumn
    //    {
    //        get;
    //        internal set;
    //    }
    //}
}

有了这三个类,下面准备一个界面,使用LocalCamera进行视频录制操作。

recordUI

需要注意的是保存操作,事实上在EncodeSession中视频的保存路径是在视频录制之前就必须指定的(当然这一点并不难理解,因为长时间的视频录制是会形成很大的文件的,保存之前缓存到内存中也不是很现实),在LocalCamera中对保存方法的封装事实上是文件的读取和删除操作。另外在这个例子中用到了前面文章中自定义的OOB控件,不明白的朋友可以查看前面的文章内容。下面是调用代码:

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Net;  
  5. using System.Windows;  
  6. using System.Windows.Controls;  
  7. using System.Windows.Documents;  
  8. using System.Windows.Input;  
  9. using System.Windows.Media;  
  10. using System.Windows.Media.Animation;  
  11. using System.Windows.Shapes;  
  12. using System.Windows.Threading;  
  13. using Cmj.MyWeb.MySilverlight.SiverlightOOB;  
  14. using Cmj.MyWeb.MySilverlight.SilverlightMeida;  
  15.   
  16. namespace SilverlightVideoRecord  
  17. {  
  18.     public partial class MainPage : UserControl  
  19.     {  
  20.         public MainPage()  
  21.         {  
  22.             InitializeComponent();  
  23.         }  
  24.   
  25.         OOBInstall install = new OOBInstall();  
  26.         LocalCamera localCamera = null;  
  27.         DispatcherTimer timer = null;  
  28.         private DateTime startTime = DateTime.Now;  
  29.         private void UserControl_Loaded(object sender, RoutedEventArgs e)  
  30.         {  
  31.             timer = new DispatcherTimer();  
  32.             timer.Interval = TimeSpan.FromSeconds(1);  
  33.             timer.Tick += new EventHandler(timer_Tick);  
  34.             if (install.IsRunOutOfBrowser)  
  35.             {  
  36.                 this.btnInstall.Visibility = Visibility.Collapsed;  
  37.                 localCamera = new LocalCamera(this,LocalCamera.AvailableVideoDevice[1].SupportedFormats[0],LocalCamera.DefaultAudioDevice.SupportedFormats[1]);  
  38.                 this.bdVideo.Child = localCamera.GetVideoRectangle();  
  39.                 //this.Tag = this.pbVolumn;  
  40.             }  
  41.             else  
  42.             {  
  43.                 this.btnInstall.Visibility = Visibility.Visible;  
  44.                 this.btnStart.IsEnabled = false;  
  45.                 this.btnPause.IsEnabled = false;  
  46.                 this.btnStop.IsEnabled = false;  
  47.                 this.btnSave.IsEnabled = false;  
  48.                 //this.tbTitleBar.IsEnabled = false;  
  49.                 //this.rbResizeButton.IsEnabled = false;  
  50.             }  
  51.         }  
  52.   
  53.         void timer_Tick(object sender, EventArgs e)  
  54.         {  
  55.             TimeSpan tsStart = new TimeSpan(startTime.Ticks);  
  56.             TimeSpan tsEnd = new TimeSpan(DateTime.Now.Ticks);  
  57.             TimeSpan tsTract = tsEnd.Subtract(tsStart);  
  58.             DateTime timeInterval = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, tsTract.Hours, tsTract.Minutes, tsTract.Seconds);  
  59.             //this.txtblkTimer.Text = string.Format("{0}:{1}:{2}", tsTract.Hours,tsTract.Minutes,tsTract.Seconds);  
  60.             this.txtblkTimer.Text = timeInterval.ToLongTimeString();  
  61.         }  
  62.   
  63.         private void btnStart_Click(object sender, RoutedEventArgs e)  
  64.         {  
  65.             localCamera.StartCaptrue();//启动视频捕获  
  66.         }  
  67.   
  68.         private void btnRecord_Click(object sender, RoutedEventArgs e)  
  69.         {  
  70.             localCamera.StartRecord();//开始录制  
  71.             this.txtblkTimer.Text = "0:00:00";  
  72.             this.startTime = DateTime.Now;  
  73.             timer.Start();  
  74.         }  
  75.   
  76.         private void btnPause_Click(object sender, RoutedEventArgs e)  
  77.         {  
  78.             localCamera.PauseRecord();//暂停录制  
  79.             timer.Stop();  
  80.         }  
  81.   
  82.         private void btnStop_Click(object sender, RoutedEventArgs e)  
  83.         {  
  84.             localCamera.StopRecord();//停止录制  
  85.             localCamera.StopCapture();//停止视频捕获  
  86.             timer.Stop();  
  87.         }  
  88.   
  89.         private void btnSave_Click(object sender, RoutedEventArgs e)  
  90.         {  
  91.             localCamera.SaveRecord();//保存视频  
  92.         }  
  93.   
  94.         private void btnInstall_Click(object sender, RoutedEventArgs e)  
  95.         {  
  96.             install.Install();  
  97.         }  
  98.     }  
  99. }  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;
using Cmj.MyWeb.MySilverlight.SiverlightOOB;
using Cmj.MyWeb.MySilverlight.SilverlightMeida;

namespace SilverlightVideoRecord
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        OOBInstall install = new OOBInstall();
        LocalCamera localCamera = null;
        DispatcherTimer timer = null;
        private DateTime startTime = DateTime.Now;
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += new EventHandler(timer_Tick);
            if (install.IsRunOutOfBrowser)
            {
                this.btnInstall.Visibility = Visibility.Collapsed;
                localCamera = new LocalCamera(this,LocalCamera.AvailableVideoDevice[1].SupportedFormats[0],LocalCamera.DefaultAudioDevice.SupportedFormats[1]);
                this.bdVideo.Child = localCamera.GetVideoRectangle();
                //this.Tag = this.pbVolumn;
            }
            else
            {
                this.btnInstall.Visibility = Visibility.Visible;
                this.btnStart.IsEnabled = false;
                this.btnPause.IsEnabled = false;
                this.btnStop.IsEnabled = false;
                this.btnSave.IsEnabled = false;
                //this.tbTitleBar.IsEnabled = false;
                //this.rbResizeButton.IsEnabled = false;
            }
        }

        void timer_Tick(object sender, EventArgs e)
        {
            TimeSpan tsStart = new TimeSpan(startTime.Ticks);
            TimeSpan tsEnd = new TimeSpan(DateTime.Now.Ticks);
            TimeSpan tsTract = tsEnd.Subtract(tsStart);
            DateTime timeInterval = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, tsTract.Hours, tsTract.Minutes, tsTract.Seconds);
            //this.txtblkTimer.Text = string.Format("{0}:{1}:{2}", tsTract.Hours,tsTract.Minutes,tsTract.Seconds);
            this.txtblkTimer.Text = timeInterval.ToLongTimeString();
        }

        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            localCamera.StartCaptrue();//启动视频捕获
        }

        private void btnRecord_Click(object sender, RoutedEventArgs e)
        {
            localCamera.StartRecord();//开始录制
            this.txtblkTimer.Text = "0:00:00";
            this.startTime = DateTime.Now;
            timer.Start();
        }

        private void btnPause_Click(object sender, RoutedEventArgs e)
        {
            localCamera.PauseRecord();//暂停录制
            timer.Stop();
        }

        private void btnStop_Click(object sender, RoutedEventArgs e)
        {
            localCamera.StopRecord();//停止录制
            localCamera.StopCapture();//停止视频捕获
            timer.Stop();
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            localCamera.SaveRecord();//保存视频
        }

        private void btnInstall_Click(object sender, RoutedEventArgs e)
        {
            install.Install();
        }
    }
}

OK,下面是视频录制的截图:

正在录制

 recordStop

停止录制后保存

saveRecord

播放录制的视频

recordVideoPlay

三、注意:

1.video sink和audio sink都是运行在不同于UI的各自的线程中,你可以使用UI的Dispathcher或者SynchronizationContext进行不同线程之间的调用。

2.在video sink和audio sink的OnSample方法中必须进行状态判断,因为sink实例创建之后就会执行OnSample方法,但此时EncodeSession还没有启动因此如果不进行状态判读就会抛出com异常。

3.视频的宽度和高度不能够随意指定,这个在NESL的帮助文档中也是特意说明的,如果任意指定同样会抛出异常。

4.最后再次提醒大家,上面的视频录制是基于NESL的因此必须将应用运行到浏览器外(OOB)。

源代码下载download

知识共享许可协议本作品采用知识共享署名 2.5 中国大陆许可协议进行许可,欢迎转载,演绎或用于商业目的。但转载请注明来自崔江涛(KenshinCui),并包含相关链接。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值