You Are Here:

Community: Developer Discussion Boards

#1 Old Lightbulb I got problems in play voice from streaming UDP - 2009-03-15, 09:51

Join Date: Sep 2008
Posts: 4
nutdiablo
Offline
Registered User
Hello every one, I'm trying to record voice in streaming and send it over UDP.
so I used Manager.createPlayer("capture://audio?encoding=pcm&rate=8000&bits=8&channels=1"); to record 0.1 sec of voice.
and send it over UDP. This part is working I got all of UDP packets,
but in receive part I got all of UDP but I can't play it.
I did try Manager.createPlayer(bis, "audio/x-wav"); it return no error but also no sound. I'm also try
pc = Manager.createPlayer("capture://audio?encoding=pcm&rate=8000&bits=8");
playback = Manager.createPlayer(bis, pc.getContentType());
it's return error Unrealized State.
what should I do?
I use E51 as sender and WTK as reciver.

And if any one could give me some sample code about RTP and RTSP for me that would be great.

Here are my Code.
thank you.
Tanan

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.control.RecordControl;
import javax.microedition.media.*;
import javax.microedition.io.*;
import java.io.*;

/**
* @author nutdiablo
*/

public class RecordAndSend extends MIDlet implements CommandListener{
// UDP
private DatagramClientHandler client;

// Player
public Player capture;
public Player playback;
public RecordControl rc;
public Player pc;

// Player Buffers
public ByteArrayOutputStream bos = new ByteArrayOutputStream();
public ByteArrayInputStream bis = null;

// GUI form
public Command rec = new Command("rec",Command.OK, 1),
stopRec = new Command("stopR",Command.STOP, 0),
stopPlay = new Command("stopP",Command.STOP, 0),
play = new Command("play",Command.OK, 1),
exit = new Command("exit",Command.EXIT, 0);
public Form init = new Form("AudioStream");

public void startApp() {
client = new DatagramClientHandler();
init.addCommand(rec);
init.addCommand(play);
init.addCommand(exit);
init.setCommandListener(this);
Display.getDisplay(this).setCurrent(init);
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

public void commandAction(Command c, Displayable s) {
if(c == exit){
notifyDestroyed();
}else if(c == rec){
init.deleteAll();
init.append("== Record Mode ==\n");
init.removeCommand(play);
init.addCommand(stopRec);
doRecord();
}else if(c == play){
init.deleteAll();
init.append("== Play Mode ==\n");
init.removeCommand(rec);
init.addCommand(stopPlay);
doPlay();
}else if(c == stopRec){
init.deleteAll();
init.append("== Stop Record Mode ==\n");
init.removeCommand(rec);
}else if(c==stopPlay){
init.deleteAll();
init.append("== Stop Play Mode ==\n");
init.removeCommand(play);
}
}

class DatagramClientHandler extends Object {

private DatagramConnection dcs, dcr;
private Datagram sendDatagram;
private Datagram receiveDatagram;

public DatagramClientHandler() {
try {
dcs = (DatagramConnection)Connector.open("datagram://192.168.1.14:8080");
//dcs = (DatagramConnection)Connector.open("datagram://localhost:8080");
} catch (IOException e) {
System.out.println("UDP send Connect : "+e.toString());
}
try {
dcr = (DatagramConnection)Connector.open("datagram://:8080");
} catch (IOException e) {
System.out.println("UDP Receive Connect : "+e.toString());
}
}

public void send(byte[] msg) throws IOException {
int length = msg.length;
System.out.println("In Send1 : "+length);
byte[] message = new byte[length];
try {
//dcs = (DatagramConnection)Connector.open("datagram://localhost:8080");
System.arraycopy(msg, 0, message, 0, length);
sendDatagram = dcs.newDatagram(message,length);
dcs.send(sendDatagram);
sendDatagram.reset();
//dcs.close();

} catch (IOException e) {
System.out.println("++++++In Send : "+e.toString());
}
}

public byte[] receive() throws IOException {
byte[] recvData = null;
try {
receiveDatagram = dcr.newDatagram(44);
dcr.receive(receiveDatagram);
recvData = receiveDatagram.getData();
int length = receiveDatagram.getLength();
receiveDatagram.reset();
System.out.println("Input size="+length);
} catch (IOException e) {
System.out.println("++++++In Reveive : "+e.toString());
}
return recvData;
}
}

public void doPlay(){
new doPlaying().start();
}

public class doPlaying extends Thread{
public void run(){
try {
init.append("Starting to receive.");
int count = 0;
while(true){
//pc = Manager.createPlayer("capture://audio?encoding=pcm&rate=8000&bits=8");
//System.out.println(pc.getContentType());
bis = new ByteArrayInputStream(client.receive());
init.append("M"+count+" : "+bis.available()+"\n");
//new g2().start();
//playback = Manager.createPlayer(bis, pc.getContentType());
playback = Manager.createPlayer(bis, "audio/x-wav");
init.append("Start Playing\n");
playback.realize();
playback.prefetch();
playback.start();
bis.reset();
playback.deallocate();
playback.close();
count++;
}
} catch (IOException ioe) {
System.out.println("++++++In Play : "+ioe.toString());
}
catch (MediaException me) {
init.append("Error: MediaException : "+me);
}
}
}

public class g2 extends Thread{
public void run(){
try {
if( bis != null){
playback = Manager.createPlayer(bis, rc.getContentType());
init.append("Start Playing\n");
playback.realize();
playback.prefetch();
playback.start();
bis.reset();
playback.deallocate();
playback.close();
}else{
init.append("Null\n");
}
} catch (IOException ioe) {
System.out.println("++++++In Play : "+ioe.toString());
}
catch (MediaException me) {
init.append("Error: MediaException : "+me);
}
}
}

public void doRecord() {
new doRecording().start();
}

public class doRecording extends Thread{
public void run(){
try{
capture = Manager.createPlayer("capture://audio?encoding=pcm&rate=8000&bits=8&channels=1");
//capture.realize();
//capture.prefetch();
//rc = (RecordControl)capture.getControl("RecordControl");
//rc.setRecordStream(bos);
for(int i=0; i<50; i++){
//capture = Manager.createPlayer("capture://audio?encoding=pcm&rate=8000&bits=8&channels=1");
capture.realize();
capture.prefetch();
rc = (RecordControl)capture.getControl("RecordControl");
rc.setRecordStream(bos);
rc.startRecord();
capture.start();
init.append("Start Record\n");
// Thread Timer
Thread.sleep(100);
capture.stop();
//init.append("Stop Record\n");
rc.stopRecord();
rc.commit();
//capture.deallocate();
//capture.close();
client.send(bos.toByteArray());

bos.flush();
init.append("Size of BOS = "+bos.size()+"\n");
bos.reset();
}
//rc.commit();
capture.deallocate();
capture.close();
client.dcs.close();
} catch (IOException ioe) {
init.append("Error: IOException : "+ioe+"\n");
} catch (MediaException me) {
init.append("Error: MediaException : "+me+"\n");
} catch (InterruptedException ie) {
init.append("Error: Doreccord : "+ie+"\n");
}
}
}
}
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible finished 3gp(h263) streaming play in MMF? wilsonho Symbian Media (Graphics & Sounds) 7 2008-06-23 11:07
RTP packet voice streaming divian Mobile Java Media (Graphics & Sounds) 0 2007-07-22 20:24
Internal UDP problems and packet monitoring dcbill Symbian Networking & Messaging 0 2005-05-06 16:10
Problems with voice files on Nokia 6600 paultreadaway Audio 6 2004-05-19 04:35
On GPRS why 6600 can not play streaming while PC using Nokia D211 can? diabol Streaming and Video 1 2004-01-19 12:39

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia