icp备案网站接入信息怎么写,wordpress 附件下载插件,桂林新闻,中山专业门户网站制作策划一直都做camera 录像功能其实知道的很少#xff0c;以前也是迷迷糊糊知道怎么写个video#xff0c;今天测试了一下#xff0c;各种问题。问题来源首先是对于SDK的阅读不够仔细。 实践的比较少。 其实所谓的录像 就是两个类的结合 一个是Camera 一个是MediaRecorder 这两个类…一直都做camera 录像功能其实知道的很少以前也是迷迷糊糊知道怎么写个video今天测试了一下各种问题。问题来源首先是对于SDK的阅读不够仔细。 实践的比较少。 其实所谓的录像 就是两个类的结合 一个是Camera 一个是MediaRecorder 这两个类搞好了轻松一直都做camera 录像功能其实知道的很少以前也是迷迷糊糊知道怎么写个video今天测试了一下各种问题。问题来源首先是对于SDK的阅读不够仔细。实践的比较少。其实所谓的录像 就是两个类的结合 一个是Camera 一个是MediaRecorder 这两个类搞好了轻松搞定。我用最简洁的代码完成录制功能。代码在后面给出下载地址。如果代码在你的手机上运行有问题可能有以下几种可能。1保存路径那里可能有问题因为我拿的机子是山寨机。你可以更改getName()函数来更改你的存储路径。2mCamcorderProfile的获取有问题你可以添加判断参考CamcorderProfile的SDK 来获取这个实例。第一部首先要让camera处于预览状态。SDK上写的很明显先给出如果要往SD卡上录制文件 还需要 另外两个权限android:nameandroid.permission.RECORD_AUDIOandroid:nameandroid.permission.WRITE_EXTERNAL_STORAGE在此感谢http://blog.csdn.net/lissdy/article/details/7039332 。为我提供了思路。To take pictures with this class, use the following steps:Obtain an instance of Camera from open(int).Get existing (default) settings with getParameters().If necessary, modify the returned Camera.Parameters objectand call setParameters(Camera.Parameters).If desired, call setDisplayOrientation(int).Important: Pass a fully initialized SurfaceHolder to setPreviewDisplay(SurfaceHolder).Without a surface, the camera will be unable to start the preview.Important: Call startPreview() tostart updating the preview surface. Preview must be started before you can take a picture.上面六条为google SDK 上 进入到预览的过程。下面开始录制部分的分析Obtain and initialize a Camera and start preview as described above.Call unlock() to allow the media processto access the camera.Pass the camera to setCamera(Camera).See MediaRecorder information about video recording.When finished recording, call reconnect() tore-acquire and re-lock the camera.If desired, restart preview and take more photos or videos.Call stopPreview() and release() asdescribed above.一开始我出现了很多问题 在于没有对这段话进行认真的分析。看第二条 unlock() 这个函数的功能是让通过使用这个函数让别的进程可以访问camera。没有调用的话会出现以下问题02-01 10:25:08.251: E/MediaRecorder(5545): start failed: -19 然后start fail了看一下SDK对于unlock ()的解释Unlocks the camera to allow another process to access it. Normally, the camera is locked to the process with an active Camera object until release() is called. To allow rapid handoff between processes, you can call this method to release the camera temporarilyfor another process to use; once the other process is done you can call reconnect() to reclaim the camera.释放camera 允许其他进程使用。一般来说照相机是被锁定到实例化后的Camera对象的除非release()被调用为了进程间的快速切换你可以调用该方法来暂时释放camera待另一个进程使用完成后你可以通过调用reconnect()方法来收回Camera。此时便是这个MediaRecorder要使用进程 所以要解锁。看第三条 setCamera(Camera)Sets a Camera to use for recording. Use this function to switch quickly between preview and capture mode without a teardownof the camera object.unlock()shouldbe called before this. Must call before prepare().设置一个用于录制的Camera 使用该方法可以快速在预览和捕捉视频模式间快速切换(不用重新获取一个Camera实例) unlock()必须在这个方法前被调用而这个方法必须在MediaRecorder.prepare()前调用。然后便是关于录制设置的了看到没这个图reset()setAudioSource()setVideoSource()setOutputFormat()setAudioEncoder()setVideoEncoder()setOutputFile()setVideoSize()setVideoFrameRate()setPreviewDisplay()prepare()start()//开始录制stop()//停止录制这个没什么说的只要你的参数选择正确就OK下面我要说的是另一个类因为MediaRecorder中有一个方法setProfile(CamcorderProfileprofile) Usesthe settings from a CamcorderProfile object for recording.设置参数用的但是它都决定哪些参数呢看一下SDK对于这个东西的理解Retrieves the predefined camcorder profile settings for camcorder applications. These settings are read-only.The compressed output from a recording session with a given CamcorderProfile contains two tracks: one for audio and one for video.Each profile specifies the following set of parameters:The file output formatVideo codec formatVideo bit rate in bits per secondVideo frame rate in frames per secondVideo frame width and height,Audio codec formatAudio bit rate in bits per second,Audio sample rateNumber of audio channels for recording.那怎么获取这个对象呢 举个简单的例子CamcorderProfilemCamcorderProfile CamcorderProfile.get(CameraInfo.CAMERA_FACING_BACK, CamcorderProfile.QUALITY_LOW);CamcorderProfile.xxxxx 你可以换成别的对应不同的数据。 但是这里返回的对象可能为空所以做好其他的处理准备这里我没有特殊处理。然后看一下setProfile()这个函数Usesthe settings from a CamcorderProfile object for recording. This method should be called after the video AND audio sources are set,andbefore setOutputFile(). If a time lapse CamcorderProfile is used, audio related source or recording parameters are ignored.使用这个类来设置录像的参数这个方法必须在setAudioSource() setVideoSource() 之后调用但是必须在setOutPutFile之前调用。如果你需要延时拍照 请参看CamCorderProfile这个类的SDK 内容。然后就开始录制了setPreviewDisplay()prepare()start()//开始录制结束录制stop方法 这时候请注意 因为你释放了camera 所以你要重新获取上面录制过程有说明When finished recording, callreconnect()tore-acquire and re-lock the camera.关于reconnect()在上面说过了这里就不解释了。最后记得释放资源 release()下面就没啥说的了。源码下载链接下载代码的链接稍后提供 http://download.csdn.net/detail/shen332401890/5272982