why isn't this working?

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
scarer's picture

Hi,
uld
I am trying to build an application that will firstly record audio and then record video. I have drupal installed locally using mamp so it is running through port 8888 in the root directory.

I have Red5 installed and running on port 5080.

I have built a flex app. The MXML just contains the interface that calls the function when the record button or stop recording button is pressed.

The connection is working and the microphone is created. I can hear the sound coming through my headphones but it isn't saving to the destination I've provided. If anyone could help me I would be eternally grateful. Just getting my head around this stuff. Here's my Action Script:

// ActionScript file
import flash.events.;
import flash.media.Microphone;
import flash.net.NetConnection;
import flash.net.NetStream;

import mx.controls.
;
import mx.rpc.events.*;
           
private var mic:Microphone;
private var connection:NetConnection;
private var publishStream:NetStream;

public var connectStatus:Boolean;
           
public function connectToServer():void
{
   //connect to server
    //create a new instance of connect
connection = new NetConnection;
    //add an event listener to the connection
  connection.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);
   //connect to the server
    connection.connect("http://localhost:5080/webapps/lectureSeries/");
  if (connectStatus = true)
  {
      mic = Microphone.getMicrophone();
      Security.showSettings(SecurityPanel.MICROPHONE);
       mic.setLoopBack(true);
         if (mic != null)
           {
              mic.setUseEchoSuppression(true);
               publishStream = new NetStream(connection);
             publishStream.attachAudio(mic);
                publishStream.publish("message", "record");
            }
          else
           Alert.show("Microphone not attached or not functioning");
    }
}

private function netStatusHandler(event:NetStatusEvent):void {
    trace(event.info.code);
    switch (event.info.code)
   {
      case "NetConnection.Connect.Success":
        //Alert.show("Connection to server a success");
      connectStatus = true;
      break;
     default:
       Alert.show("Media server connection error.");
        connectStatus = false;
}
}

private function stopRecording():void
{
   publishStream.close();
}

Thanks!

Sarah

Comments

i managed to fix it :)

scarer's picture

now working.

if you have a question please ask :)

send failed error + webcam problems

scarer's picture

I am getting the error message send failed when I try to run a flex app from another computer.

I am logged in as admin on the drupal instance on the server (my mac).

I am also having big problems with trying to attach video.

1061: Call to possibly undefined method attachNetStream through a reference with static type flash.net.stream

on this line of code:

publishStream.attachNetStream(cam);

then when i try:

publishStream.attachVideo(cam);

I get this error:

1061: Call to possibly undefined method attachVideo through a reference with static type flash.net.stream

I am trying to publish the stream from a webcam called 'cam' that I created with var cam:Camera = Camera.getCamera(); to my red5 server.

The audio stream is working but the webcam is not.

Please help!

same stream? or two seperate ones?

scarer's picture

to get input from the user's microphone and webcam simultaneously, do the streams need to be seperate?

can they be attached to the same stream?

please help!

thanks,

sarah

Only one stream is needed.

newms's picture

Only one stream is needed.

this is my code in the function

scarer's picture

private function netStatusHandler(event:NetStatusEvent):void {
   trace(event.info.code);
    switch (event.info.code)
   {
      case "NetConnection.Connect.Success":
        //Alert.show("Connection to server a success");
      connectStatus = true;
      if (connectStatus = true)
      {
      mic = Microphone.getMicrophone();
      cam = Camera.getCamera();
      //var vid:Video = new Video;
       cam.setMode( 640, 480, 15 );
       cam.setQuality( 0, 65 );
       stopRecord.enabled = true;
     makeRecord.enabled = false;
            if (mic != null)
           {
              mic.setLoopBack(true);
             //Security.showSettings(SecurityPanel.MICROPHONE);
             mic.setUseEchoSuppression(true);
               publishStream = new NetStream(connection);
             publishStream.attachAudio(mic);
                //publishStream.attachCamera(cam);
             if (cam == null)
               {
                  Alert.show("User has no camera installed");
              }
              else if (cam != null)
              {
                  /var vid:Video = new Video;
                   vid.attachCamera(cam);
                 addChild(vid);
/
                   publishStream.attachCamera(cam);
               }
              //publishStream.attachVideo(cam);
              var storeNumber:Number = now.valueOf();
                //timestamp = storeNumber.toString();
              publishStream.publish("message_" + yourName.text, "record");
               filename = "message_" + yourName.text + ".flv";
            }
          else
           Alert.show("Microphone not attached or not functioning");
        }
      break;
     default:
       Alert.show("Media server connection error.");
        connectStatus = false;
}
}

i've got it working

scarer's picture

I have my file saving to the Red5 server with video and audio and have also developed a module to embed the flex interface in comments to record this data.

I am having issues playing back the data in Drupal.

I am saving the data into the body of the comment as:

The sound plays but the video doesn't.

I tried linking it to another video I have on my Red5 server and this plays fine. I also tried viewing the video from it's locaiton on the server and the video data is being stored fine.

Has it got something to do with the data that is stored that accompanies the video? I.e. metadata? I am trying to currently work out how to store the Framerate, duration, size, width and height of the file.

Am I barking up the wrong tree?

Please help.

Thanks,

Sarah

do you have to encode the video?

scarer's picture

? how do you do this with data that is captured and stored using the user's webcam?

please help!

scarer's picture

Hi,

I have tried embedding a flv that I recorded to the Red5 server. The ones that are pre-recorded examples i.e. IronMan, Spiderman etc. play fine with the code but the ones I have captured using the webcam with flex don't play video they only play sound. I am trying to understand what the difference is between the two files that prevents the one that is being saved to the server via webcam from playing properly.

This is my code (I put it in-between php tags cause the editor didn't like it otherwise):
[code]

<?php
<embed src="http://mysite/player.swf" bgcolor="#ffffff" width="330" height="270" name="player" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="file=rtmp://mysite/myvideo.flv&width=330&height=270"/>
?>

[/code]
Is there a flashvar that can be set? Or am I not capturing the adaquate data when I save the file to the server for it to be played back by the flash player?

Please help!

Thanks,

Sarah

scarer's picture

I'm trying to embed this in a comment body. It's still not working:

<script type="text/java_script">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0','width','160','height','120','id','FLVPlayer','src','?q=modules/flexRecord/FLVPlayer_Progressive','flashvars','&MM_ComponentVersion=1&skinName=?q=modules/flexRecord/Clear_Skin_1&streamName=rtmp://myred5server/oflaDemo/myvideo&autoPlay=true&autoRewind=false','quality','high','scale','noscale','name','FLVPlayer','salign','lt','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','?q=modules/flexRecord/FLVPlayer_Progressive' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="160" height="120" id="FLVPlayer">
  <param name="movie" value="?q=modules/flexRecord/FLVPlayer_Progressive.swf" />
  <param name="salign" value="lt" />
  <param name="quality" value="high" />
  <param name="scale" value="noscale" />
  <param name="FlashVars" value="&MM_ComponentVersion=1&skinName=?q=modules/flexRecord/Clear_Skin_1&streamName=rtmp://myred5server/oflaDemo/myvideo&autoPlay=true&autoRewind=false" />
  <embed src="?q=modules/flexRecord/FLVPlayer_Progressive.swf" flashvars="&MM_ComponentVersion=1&skinName=?q=modules/flexRecord/Clear_Skin_1&streamName=rtmp://myred5server/oflaDemo/myvideo&autoPlay=true&autoRewind=false" quality="high" scale="noscale" width="160" height="120" name="FLVPlayer" salign="LT" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" />
</object></noscript>

voice recording

NehaP's picture

hi
Actually i m trying to record my voice through mic and then trying to play it back. My code is almost similar to the one that u have posted in ur frst post. the file gets saved to the required destination but when i try to play it back no sound comes. also the file that gets formed is only 1 kb always even if i record for a longer time. So actually i think nothing gets saved in the file.
i will really grateful if u could help. My code is like this:

import mx.controls.Alert;
import flash.events.*;
import flash.media.Microphone;
import flash.net.NetConnection;
import flash.net.NetStream;

        import mx.rpc.events.*;


    // Author: Vishesh Sharma aka Nemesis
    // Date Edited: 12/19/08
    //Copyright: All rights reserved with Chandigarh CME, Infosys Technologies Limited


    var myNetConn:NetConnection=new NetConnection();;
    var event:NetStatusEvent;

    private function Say():void{

        joinlisten.enabled = true;

        myNetConn.connect("rtmp://localhost/testNeha");
        myNetConn.addEventListener(NetStatusEvent.NET_STATUS, OnConnect);

    }

    private function OnConnect(event):void {

            var myNetStream:NetStream;


            // Create Microphone Obj
            /* var myMike:Microphone; 
            myMike = Microphone.getMicrophone();
                myMike.setUseEchoSuppression(true);*/
         var mic:Microphone = Microphone.getMicrophone();
         Security.showSettings(SecurityPanel.MICROPHONE);

         if (mic != null)
          {

             mic.setUseEchoSuppression(true);
               mic.setLoopBack(true);
             myNetStream = new NetStream(myNetConn);
             mic.addEventListener(ActivityEvent.ACTIVITY, activityHandler);
             mic.addEventListener(StatusEvent.STATUS, statusHandler);
             myNetStream.attachAudio(mic);

             myNetStream.publish("message", "record");
             joinsay.enabled = true;
            }
        else
            Alert.show("Microphone not attached or not functioning");



    }
    private function activityHandler(event:ActivityEvent):void {
        trace("activityHandler: " + event);
    }

    private function statusHandler(event:StatusEvent):void {
        trace("statusHandler: " + event);
    }
    private function Listen():void{

        joinsay.enabled = false;
        joinlisten.enabled = true;

        myNetConn.connect("rtmp://localhost/testNeha");
        myNetConn.addEventListener(NetStatusEvent.NET_STATUS, OnConnecting);
    }


    private function OnConnecting(event):void {

            var play_ns:NetStream = new NetStream(myNetConn);

            // Create Microphone Obj

            //Attach Audio from Microphone
            //myNetStream.attachAudio(play_ns);
             var video:Video = new Video();


            video.attachNetStream(play_ns);

            play_ns.play("message",1,5,true);



    }

thanks in advance.

neha

serverside script

linuxbox-gdo's picture

Hello there folks. I was searching for how to attach the captured microphone data and send it to a script for saving to a file and found this site. i have a few questions.

First, what is the format of the captured sound? i mean, is the flash player encoding it and sending it in the stream or what? is it an mp3 or mp4 and what is the datarate like kbps and such? i know human voice really doesn't need anything more than 64kbps and actually 48 kbps sounds good with aac mp4 for the human voice.

Second question is on the server side scripting. what language are you using and can PHP be used to capture the stream for saving the file? I have a lot of experience with PHP so I was hoping that PHP can be used to capture the audio stream.

Thanks for your help!

you can get it all "out of the box".

ariel_hitron's picture

hi,
you can check out the kaltura module which has webcam recording built in.
already has some integration with Comments to produce video comments
see demo here: http://drupal.kaltura.org/demo/?q=node/75#comments
login with demo/demo to make your own comment.
module page is here: http://drupal.org/project/kaltura

flash components are configurable and open source, so you can customize them if you'd like.

Hope this helps...
Ariel.

Object Embedding (Flash)

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week