Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

OW40

Como faço para limitar o tempo de gravação?

Recommended Posts

Ola boa noite,

 

Eu sou totalmente iniciante em Flash / Action Script e estou com um problema para resolver e acredito que aqui eu encontre a solução.

Estou precisando limitar o tempo da gravação do usuário tipo para 1 minuto, porém ja tentei limitar com nTimer = setInterval(stopRecording, 60000); dentro actionscript exemplo da Adobe, mas não esta funcionandoi. Ja fui no site da Adobe e mesmo assim não consegui compreender onde esta o erro.

 

Estou postando abaixo o Action da Adobe que esta funcionando perfeitamente, oq ue eu realmente gostaria era apenas limitar o tempo da gravação.

 

Agradeço muito se alguém puder me ajudar.

 

////////////////////////////////////////////////////////////////////////
//
// Flash Media Server Demonstration App: Publish / Subscribe
// Sample Code copyright 2006 Adobe Systems
//
////////////////////////////////////////////////////////////////////////

// connection & stream name text variables
var fms_url:String = "rtmp://localhost/simpleLive/";
var streamName:String = "recording";

// record & replay Netstream objects
var record_ns:NetStream;
var replay_ns:NetStream;

//debug text area
var debug_ta:mx.controls.TextArea;

//publish type constants
var kREC:Number = 1;
var kLIVE:Number = 2;
var kREP:Number = 3;

//init publish type
setPublishType(kLIVE);

//audio sample rate array
var sampleRate_array:Array = new Array(5, 8, 11, 22, 44);

//get Cam & set quality
var client_cam = Camera.get();
client_cam.setQuality(0,100);

//get Mic & set sample rate
var client_mic = Microphone.get();
client_mic.setRate(sampleRate_array[4]); //44.1k Hz

//////////////////////////////////////
//FMS app URL textfield
fms_app_url.autoSize = false;
fms_app_url.text = fms_url;
fms_app_url.type = "input";
fms_app_url.border = true;
debugtxt(fms_app_url.text);

////////////////////////////////////////
// FMS Instance textfield
fms_recording.text = streamName;

debugtxt(fms_recording.text);

//attach Cam to Live Video stage object
Live_Video.attachVideo(client_cam);

// init Event listeners
var connectBtnListener:Object = new Object();
var recBtnListener:Object = new Object();
var repBtnListener:Object = new Object();
var camBtnListener:Object = new Object();
var nsBufListener:Object = new Object();
var nsBufPBListener:Object = new Object();
var clearDBListener:Object = new Object();

// set the button event listeners to functions
Connect_btn.addEventListener("click", connectBtnListener);

Record_btn.addEventListener("click", recBtnListener);

Replay_btn.addEventListener("click", repBtnListener);

SetCamera_btn.addEventListener("click", camBtnListener);

nsBuf_btn.addEventListener("click", nsBufListener);

clearDebug_btn.addEventListener("click", clearDBListener);

nsBufPB_btn.addEventListener("click", nsBufPBListener);

connectBtnListener.click = function(eventObj:Object)
{
debugtxt("[Connect]");
connectClicked();
}

recBtnListener.click = function(eventObj:Object)
{
recordClicked();
}

repBtnListener.click = function(eventObj:Object) 
{
replayClicked(true);
}

//set Camera properties
camBtnListener.click = function(eventObj:Object) 
{
debugtxt("[SetCAM]");

var camBW:Number = cam_bw.text;
var camQual:Number = cam_qual.text;

var camWide:Number = cam_wide.text;
var camHi:Number = cam_height.text;
var camFrPS:Number = cam_setfps.text;
var kfi:Number = cam_kfi.text;

debugtxt("camBW= " + camBW);
debugtxt("camQual= " + camQual);

debugtxt("camWide= " + camWide);
debugtxt("camHi= " + camHi);
debugtxt("camFrPS= " + camFrPS + newline);

client_cam.setQuality(camBW,camQual);
client_cam.setMode(camWide, camHi, camFrPS);
client_cam.setKeyFrameInterval(kfi);
}

//set Record Netstream buffer time
nsBufListener.click = function(eventObj:Object) 
{
debugtxt("[SetRec NS]");

var nsBufr:Number = ns_buf.text;
debugtxt("RecnsBuffer= " + nsBufr);
record_ns.setBufferTime(nsBufr);
}

//set Replay Netstream buffer time
nsBufPBListener.click = function(eventObj:Object) 
{
debugtxt("[SetPB NS]");

var nsBufr2:Number = ns_bufPB.text;
debugtxt("PBnsBuffer= " + nsBufr2);
replay_ns.setBufferTime(nsBufr2);
}

//clear debug text area
clearDBListener.click = function(eventObj:Object)
{
debug_ta.text = " ";
debug_ta.vPosition = debug_ta.maxVPosition
}

/////////////////////////////////////////////////
// Connect Button
function connectClicked()
{
if(Connect_btn.getLabel() == "Connect"){
client_nc.connect(fms_app_url.text);
mcConnectionLight.connect(client_nc);
}else{
Connect_btn.setLabel("Connect");
closeRecord(true);
closeReplay(true);
client_nc.close();
}
}
/////////////////////////////////////////////////
// Record Button
function recordClicked()
{
if(Record_btn.getLabel() == "Publish"){
// Attach data from the video and audio devices to the output stream
record_ns.attachVideo(client_cam);

// Then publish the camera output as a recorded stream
debugtxt("pub type = " + st_publishType);
record_ns.publish(fms_recording.text,st_publishType);

Record_btn.setLabel("Stop");
Record_btn.setStyle("themeColor", "0xFF0000");
debugtxt("***recording***");
}else{
record_ns.close();
Record_btn.setLabel("Publish");
debugtxt("recording stopped");
Record_btn.setStyle("themeColor", "0xcccccc");
}
}

////////////////////////////////////////////////////
// Replay Button
function replayClicked(clicked:Boolean)
{
debugtxt("ReplayClicked = " + (clicked == false ? "false":"true"));
if(Replay_btn.getLabel() == "Replay"){
replay_ns.play(fms_recording.text);
Replay_btn.setLabel("Stop");
Replay_btn.setStyle("themeColor", "0x00ff00");
debugtxt("***replaying***");

}else{
Replay_btn.setLabel("Replay");
if(clicked == true){
replay_ns.close();
}
Replay_btn.setStyle("themeColor", "0xcccccc");
}
}
//////////////////////////////////////////////////////
// open streams & set buttons
function openStreams():Void
{
Record_btn.enabled = true;
Replay_btn.enabled = true;
initStreams(client_nc);
}

//////////////////////////////////////////////////////
// close Record stream & reset button
function closeRecord(disableBtn:Boolean):Void
{
record_ns.close();
Record_btn.setLabel("Publish");
if(disableBtn == true)
Record_btn.enabled = false;
}
//////////////////////////////////////////////////////
// close Replay stream & reset button
function closeReplay(disableBtn:Boolean):Void
{
replay_ns.close();
Replay_btn.setLabel("Replay");
if(disableBtn == true)
Replay_btn.enabled = false;
}

//////////////////////////////////////////////////////
// NetConnection object
var client_nc:NetConnection = new NetConnection();

//////////////////////////////////////////////////////
// Get Connection Success status
client_nc.onStatus = function(ncInfoObj:Object):Void {
debugtxt(ncInfoObj.code);
if (ncInfoObj.code == "NetConnection.Connect.Success") {
Connect_btn.setLabel("Close");
openStreams();
}
};

//////////////////////////////////////////////////////
// init streams
function initStreams(this_client_nc:NetConnection)
{
debugtxt("initStreams");
// Create an input stream to playback the video, and attach
// video on that stream to the Replay_video object
replay_ns = new NetStream(this_client_nc);

//always a good practice to set the NS buffer (seconds)
replay_ns.setBufferTime(0.1);

replay_ns.onStatus = function(infoObject:Object):Void {
debugtxt("replay_ns_onStatus");

for( var prop in infoObject){
debugtxt(prop + ": " + infoObject[prop]);
}
debugtxt(" ");

/////// Stop
if (infoObject.code == "NetStream.Play.Stop") {
debugtxt("*** Netstream Stopped ***");
}
}

replay_ns.onPlayStatus = function(infoObject:Object):Void{
debugtxt("onPlayStatus");
for( var prop in infoObject){
debugtxt(prop + ": " + infoObject[prop]);
}
debugtxt(" ");
replayClicked(false);
}

Replay_Video.attachVideo(replay_ns);

/////////////////////////////////////////////////////
//Create output stream used to publish the video
record_ns = new NetStream(this_client_nc);
record_ns.onStatus = function(infoObject:Object):Void {
debugtxt("record_ns_onStatus");

for( var prop in infoObject){
debugtxt(prop + ": " + infoObject[prop]);
}
debugtxt(" ");
}
Live_Video.attachVideo(client_cam);
record_ns.attachAudio(client_mic);

////////////////////////////////////////////////////
//record debug text

var debug1_interval:Number = setInterval(debug1Thing, 100, record_ns);

////replay debug text

var debug2_interval:Number = setInterval(debug2Thing, 100, replay_ns);
}

///////////////////////////////////////////////////////
//debug texts
function debug1Thing(that_ns:NetStream) {
debug1_txt.text = "time: "+Math.floor(that_ns.time); 
cam_fps.text = client_cam.currentFps;
}
function debug2Thing(that_ns:NetStream) {
debug2_txt.text = "time: "+Math.floor(that_ns.time);

}

///////////////////////////////////////////////////
// mic audio level
var activityLevel_pb:mx.controls.ProgressBar;
activityLevel_pb.mode = "manual";
activityLevel_pb.label = "Mic check: %3%%";
activityLevel_pb.setStyle("themeColor", "0xFF0000");

////////////////////////////////////////////////////
// Audio montoring

//this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth());
//var active_mic:Microphone = Microphone.get();
//sound_mc.attachAudio(active_mic);

this.onEnterFrame = function() {
activityLevel_pb.setProgress(client_mic.activityLevel, 100);
};

client_mic.onActivity = function(active:Boolean) {
if (active) {
var haloTheme_str:String = "haloGreen";
} else {
var haloTheme_str:String = "0xFF0000";
}
activityLevel_pb.setStyle("themeColor", haloTheme_str);
};

////////////////////////////////////////////////////
// publish type radiobuttons
var publishtypeListener:Object = new Object();
publishtypeListener.click = function(eventObj:Object)
{
debugtxt("click");
for(i in eventObj){
debugtxt(i + ": " + eventObj[i]);
}
publishType = eventObj.target.data;

setPublishType(publishType);
}

function setPublishType(type:Number):Void
{
switch(type){
case 1:
st_publishType = "record";
rad_record.selected = true;
rad_live.selected = false;
rad_append.selected = false;
break;
case 2:
st_publishType = "live";
rad_record.selected = false;
rad_live.selected = true;
rad_append.selected = false;
break;
case 3:
st_publishType = "append";
rad_record.selected = false;
rad_live.selected = false;
rad_append.selected = true;
break;
}
}

///////////////////////////////////////////////////
//Publish type radio buttons
rad_record.addEventListener('click', publishtypeListener);
//var rad_live:mx.controls.RadioButton;
rad_live.addEventListener('click', publishtypeListener);
//var rad_append:mx.controls.RadioButton;
rad_append.addEventListener('click', publishtypeListener);

////////////////////////////////////////////////////
// Audio SampleRate radio buttons
var sampleRateListener:Object = new Object();
sampleRateListener.click = function(eventObj:Object)
{
debugtxt("click");
for(i in eventObj){
debugtxt(i + ": " + eventObj[i]);
}
var sr = eventObj.target.data;

rad_44.selected = false;
rad_22.selected = false;
rad_11.selected = false;
rad_8.selected = false;
rad_5.selected = false;

client_mic.setRate(sampleRate_array[sr]);

switch(sr){
case 4:
rad_44.selected = true;
break;
case 3:
rad_22.selected = true;
break;
case 2:
rad_11.selected = true;
break;
case 1:
rad_8.selected = true;
break;
case 0:
rad_5.selected = true;
break;
}
debugtxt("sampleRate= " + sampleRate_array[sr]);
}

//audio samplerate radio buttons
rad_44.addEventListener('click', sampleRateListener);
rad_22.addEventListener('click', sampleRateListener);
rad_11.addEventListener('click', sampleRateListener);
rad_8.addEventListener('click', sampleRateListener);
rad_5.addEventListener('click', sampleRateListener);

//////////////////////////////////////
// genral debug text area
function debugtxt(txt:String)
{
//trace(txt);
debug_ta.text += txt;
debug_ta.text += newline;
debug_ta.vPosition = debug_ta.maxVPosition;
}

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.