[FMS]AS3.0基于FMS写的录音机代码示例
[FMS]AS3.0基于FMS写的录音机代码示例,基本具备的功能,录音,暂停录音,重新录音,播放录音,暂停播放录音,以及停止播放
基本具备的功能,录音,暂停录音,重新录音,播放录音,暂停播放录音,以及停止播放。
类机构如下
核心录音
- package com.DNight
- {
- import flash.events.EventDispatcher;
- import flash.media.Microphone;
- import flash.net.NetConnection;
- import flash.net.NetStream;
- import flash.events.NetStatusEvent;
- import flash.utils.setInterval;
- import flash.utils.clearInterval;
- import com.DNight.events.RecorderEvent
- /**
- * ...
- * @author DN
- */
- public class Recorder extends EventDispatcher
- {
- internal static const FMSSTR:String = "rtmp://localhost/FMSRecord";
//极酷cuplayer提示:rtmp服务器地址- public static const FMS_TOTAL_TIME:int = 10;
- private var _netConnection:NetConnection;
- private var _netStream:NetStream;
- private var _mic:Microphone;
- private var _recordRember:int = 0;
- private var _recordName:String;
- private var _recordingTime:int = 0;
- private var _intervalId:uint;
- public function get mic():Microphone {
- return _mic
- }
- public function get recordName():String {
- return _recordName;
- }
- public function Recorder()
- {
- _netConnection = new NetConnection();
- _netConnection.connect(Recorder.FMSSTR);
- _netConnection.addEventListener(NetStatusEvent.NET_STATUS, onNetStatusHandle);
- _mic = Microphone.getMicrophone();
- _mic.gain = 60;
- _mic.rate = 11;
- _mic.setUseEchoSuppression(true);
- _mic.setLoopBack(true);
- _mic.setSilenceLevel(5, 1000);
- }
- private function onNetStatusHandle(event:NetStatusEvent) {
- switch(event.info.code) {
- case "NetConnection.Connect.Success":
- trace("连接成功");
- _netStream = new NetStream(_netConnection);
- break
- case "NetConnection.Connect.Failed":
- trace("连接失败");
- break
- }
- }
- public function startRecord() {
- if (_recordRember == 0) {
- //trace("第一次开始录制");
- var nowTime:Date = new Date();
- _recordName = nowTime.getTime().toString();
- _netStream.attachAudio(_mic);
- _netStream.publish(_recordName,"record");
- _recordRember = 1;
- }else {
- //trace("继续录制");
- _netStream.publish(_recordName,"append");
- }
- _intervalId=setInterval(upData,1000);
- }
- public function pauseRecord() {
- //trace("暂停录制");
- _netStream.close();
- clearInterval(_intervalId);
- }
- public function stopRecord() {
- //trace("停止录制,重新录制");
- _netStream.close();
- _recordRember = 0;
- clearInterval(_intervalId);
- _recordingTime = 0;
- }
- private function upData() {
- _recordingTime++;
- if (_recordingTime<=Recorder.FMS_TOTAL_TIME) {
- var recordProgress:RecorderEvent = new RecorderEvent(RecorderEvent.RECORD_PROGRESS);
- this.dispatchEvent(recordProgress);
- }else {
- var recordEnd:RecorderEvent = new RecorderEvent(RecorderEvent.RECORD_END);
- this.dispatchEvent(recordEnd);
- clearInterval(_intervalId);
- _recordingTime = 0;
- }
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...