Home  | My Account  |  Membership
WorldDeveloper.org
Forum Details
Topics
Posts
Categories
 
577 member(s)
718,905 hit(s)
14 categories
51 topics
26 messages
0 online
Author Topics Replies Views Last Updated
subhankar1981
1 topic(s)
0 post(s)
Audio in not Recording 0 3737 September 20, 2011 7:45 AM

Actually when i am recording video from mobile camera it is recording as a byte array, after thet through Http coonection i am genarating the .3gp file, but when i am palyaing the .3gp file avideo is playing fine but audio is not playing, when i chacked the descriotion it showing the the video aspect ratio,bitrate ,format,selected codec etc... , but there is no information about Audio. please help me whre i am doing wrong.

Here is the code to upload the file in server:

package com.sisatellabs.j2me.job;

import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;

import com.sisatellabs.j2me.VideoNote;
import com.sisatellabs.j2me.prefs.SystemPreferences;
import com.sisatellabs.j2me.ui.CommunicatingScreen;
import com.sisatellabs.j2me.ui.LogScreen;
import com.sisatellabs.j2me.ui.RecordScreen;

public class UploadJob implements Runnable
{
protected String name;
protected ByteArrayOutputStream baos;

public UploadJob(String name, ByteArrayOutputStream baos)
{

this.name = name;
this.baos = baos;
}


public void run()
{
VideoNote.instance.display.setCurrent(new CommunicatingScreen());

HttpConnection c = null;
DataInputStream is = null;
DataOutputStream os = null;

try
{
String uploadURL = VideoNote.instance.getAppProperty("http://www.sisatel.com") + "/socialad/m_input.php";
long protocolId = 1L;

String username = SystemPreferences.instance.get("account.username");
String password = SystemPreferences.instance.get("account.password");

c = (HttpConnection) Connector.open(uploadURL,Connector.READ_WRITE);

c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("Connection", "keep-alive");

os = c.openDataOutputStream();
os.writeLong(protocolId);

os.writeUTF(username);
os.writeUTF(password);
os.writeUTF(name);

byte[] data = baos.toByteArray();
baos.reset();
baos = null;

os.writeInt(data.length);
os.write(data);
os.flush();

is = c.openDataInputStream();
int rc = is.readInt();
}
catch (Exception e)
{
LogScreen.instance.log(e);
}
finally
{
if (is != null)
{
try
{
is.close();
}
catch (Exception e)
{
}
}
if (c != null)
{
try
{
c.close();
}
catch (Exception e)
{
}
}
baos = null;
System.gc();
}


VideoNote.instance.display.setCurrent(RecordScreen.instance);
}
}


Here is code of video recording:

// Java Document
package com.sisatellabs.j2me.ui;

import java.io.ByteArrayOutputStream;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.RecordControl;
import javax.microedition.media.control.VideoControl;

import com.sisatellabs.j2me.job.JobRunner;
import com.sisatellabs.j2me.job.UploadJob;


public class RecordScreen extends ScreenCanvas implements CommandListener, Runnable
{
public static final RecordScreen instance = new RecordScreen();

private Command CMD_START = new Command("Start", Command.BACK, 1);
private Command CMD_STOP = new Command("Stop", Command.OK, 1);
private Player p = null;
private RecordControl rc = null;
private VideoControl videoControl = null;
private Thread thread;
private long startTime = 0;

private ByteArrayOutputStream baos = new ByteArrayOutputStream(1024*500);
private boolean running = false;

private RecordScreen()
{
this.addCommand(CMD_STOP);
this.addCommand(CMD_START);
this.setCommandListener(this);
}

public void initialize()
{
}

public void commandAction(Command c, Displayable d)
{
if (c == CMD_START)
{
start();
}
else if (c == CMD_STOP)
{
stop();
}
}

protected void start()
{
try
{
if (!running)
{
if (thread == null)
{
startTime = System.currentTimeMillis();
thread = new Thread(this);
thread.start();

baos.reset();

p = Manager.createPlayer("capture://video");
p.realize();
rc = (RecordControl) p.getControl("RecordControl");




videoControl = (VideoControl) (p.getControl("VideoControl"));
videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
videoControl.setVisible(true);

int x = (getWidth() - videoControl.getDisplayWidth()) >> 1;
int y = (getHeight() - videoControl.getDisplayHeight()) >> 1;
videoControl.setDisplayLocation(x, y);



rc.setRecordStream(baos);
p.prefetch();

rc.startRecord();
p.start();

repaint();

running = true;
}
}
}
catch (Exception e)
{
LogScreen.instance.log(e);
}
}

protected void stop()
{
if (running)
{
try
{
thread = null;

rc.stopRecord();
rc.commit();
p.stop();
p.deallocate();
p.close();



JobRunner.instance.run(new UploadJob("sisatelmob.3gpp", baos));

p = null;
rc = null;
}
catch (Exception e)
{
LogScreen.instance.log(e);
}
finally
{
running = false;
}
}
}


public void run()
{
while (thread != null)
{


try
{
Thread.sleep(1000);
}
catch (Exception e)
{
}
}
}

protected void paint(Graphics g)
{
drawHeaderAndFooter(g," Start recording >");

int w = getWidth();
int h = getHeight();

int dy = g.getFont().getHeight() + 2;
int starty = (h >> 1) - (dy/2);

if ( running )
{
long elapsed = (System.currentTimeMillis() - startTime)/1000;
String timeString = String.valueOf(elapsed/60);
long sec = elapsed % 60;
timeString += ( sec 10 ) ? ":0" + sec : ":" + sec;

g.drawString(timeString, w >> 1, starty, Graphics.TOP | Graphics.HCENTER);
}
else
{
g.drawString("Record Ready", w >> 1, starty, Graphics.TOP | Graphics.HCENTER);
}

}
}

Here is the PHP code where file is genarting(m_input.php):
$postdata = file_get_contents("php://input");
$fp = fopen(time()."-mob.3gp","a+");
// fwrite($fp, $GLOBALS['HTTP_RAW_POST_DATA']);
fwrite($fp, $postdata);
//fclose($fp);


Helese help me where i am doing wrong

Thank you

©2008 WorldDeveloper.org - PO Box 310575 Miami, FL 33231

WorldDeveloper.org is a managed social network for application developers around the world.