MSoundCapture and MSoundPlayback

Some of my students (and myself) were having trouble with the Mary Jane Soft MSound library so I put together very quick and dirty style libraries: MSoundCapture and MSoundPlayback

Download them: MSoundCapture, MSoundPlayback

Here is some example code:

import processing.core.*;
import com.mobvcasting.msoundcapture.*;
import com.mobvcasting.msoundplayback.*;

public class MSoundCaptureTest extends PMIDlet
{
MSoundPlayback sndplay;
MSoundCapture sndcap;
byte[] soundData;

String mimeType;

String captureKey = "Capture";
String stopCaptureKey = "Stop Capture";
String playKey = "Play Sound";

public void setup()
{
softkey(captureKey);

sndcap = new MSoundCapture((PMIDlet)this);
}

public void draw()
{
}

public void softkeyPressed(String label)
{
if (label.equals(captureKey))
{
sndcap.startCapture();
softkey(stopCaptureKey);
}
else if (label.equals(stopCaptureKey))
{
mimeType = sndcap.getCapturedType();
sndcap.stopCapture();
}
else if (label.equals(playKey))
{
sndplay = new MSoundPlayback(this,soundData,mimeType);
sndplay.playSound();
}
redraw();
}

public void libraryEvent(Object library, int event, Object data)
{
if (library.getClass().isInstance(sndcap) && event ==
MSoundCapture.CAPTURE_COMPLETE)
{
soundData = (byte[])data;
mimeType = sndcap.getCapturedType();
softkey(playKey);
redraw();
}
}
}

MMMSMessaging Library

In my ongoing series of libraries for Mobile Processing, I put together a library for sending MMS Messages. You can download the library and the source.

Here is a quick example using it (this example also uses my MVideoCapture library):

import processing.core.*;

import com.mobvcasting.mmmsmessaging.*;
import com.mobvcasting.mvideocapture.*;

public class MMMSMessagingTest extends PMIDlet
{
MMMSMessaging mms;

MVideoCapture vidcap;

String captureKey = "Capture Video";
String stopKey = "Stop Capture";
String sendMessageKey = "Send Message";
String statusMessage = "";

byte[] outputArray;

//public static int MAX_MESSAGE_SIZE = 307200;
public static int MAX_MESSAGE_SIZE = 305000;

public void setup()
{
mms = new MMMSMessaging(this);
vidcap = new MVideoCapture(this);

softkey(captureKey);

noLoop();
}

public void draw()
{
background(255);
}

public void softkeyPressed(String label)
{
if (label.equals(sendMessageKey))
{
if (outputArray.length < MAX_MESSAGE_SIZE)
{
mms.sendMMS("youremailorphonenumber","subject","body",outputArray,"video/3gpp","avideo.3gp");
}
else
{
// Too big, divide up
int numSegments = (int)Math.ceil((double)((double)outputArray.length/(double)MAX_MESSAGE_SIZE));
for (int i = 0; i < numSegments; i++)
{
byte[] newOutputArray;

if (i < numSegments - 1)
{
newOutputArray = new byte[MAX_MESSAGE_SIZE];
System.arraycopy(outputArray, i*MAX_MESSAGE_SIZE, newOutputArray, 0, MAX_MESSAGE_SIZE);
}
else
{
newOutputArray = new byte[outputArray.length - i*MAX_MESSAGE_SIZE];
System.arraycopy(outputArray, i*MAX_MESSAGE_SIZE, newOutputArray, 0, newOutputArray.length);
}
mms.sendMMS("youremailorphonenumber","subject part " + (i+1) + " of " + numSegments,"body",newOutputArray,"video/3gpp","avideo_part_" + i + ".3gp");
}
}
}
else if (label.equals(captureKey))
{
softkey(stopKey);
vidcap.showCamera();
vidcap.startCapture();
}
else if (label.equals(stopKey))
{
softkey(sendMessageKey);
vidcap.stopCapture();
vidcap.hideCamera();
outputArray = vidcap.getCapturedVideo();
}
}
}

You can find more examples and a discussion on using this library from my course Mobile Media Week 7 notes

MHTTPFilePoster Library

Along with my MVideoCapture and MVideoPlayback libraries, I needed to develop a means to post those files to the web through standard HTTP. For this reason, I put together this library.

You can download the library and source.

Here is an example which also uses the MVideoCapture library:

import processing.core.*;

import com.mobvcasting.mhttpfileposter.*;
import com.mobvcasting.mvideocapture.*;

public class MHTTPFilePosterTest extends PMIDlet
{
MVideoCapture vidcap;
MHTTPFilePoster poster;

String captureKey = "Capture Video";
String stopKey = "Stop Capture";
String uploadKey = "Upload Video";
String uploadStatus = "Check Upload";

String statusMessage = "Not Captured";

byte[] outputArray;

PFont font;

public void setup()
{
vidcap = new MVideoCapture(this);

softkey(captureKey);
font = loadFont("ArialMT-12.mvlw");
textFont(font);
}

public void draw()
{
background(255);
text(statusMessage,10,15);
}

public void softkeyPressed(String label)
{
if (label.equals(captureKey))
{
softkey(stopKey);
vidcap.showCamera();
vidcap.startCapture();
}
else if (label.equals(stopKey))
{
softkey(uploadKey);
vidcap.stopCapture();
vidcap.hideCamera();
outputArray = vidcap.getCapturedVideo();
//outputArray = new byte[]{(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff};
}
else if (label.equals(uploadKey))
{
poster = new MHTTPFilePoster(this, "http://your.server/upload.php", "avideofile", "bytes", outputArray);
poster.startUpload();
statusMessage = "Uploading Video";
softkey(uploadStatus);
}
else if (label.equals(uploadStatus))
{
statusMessage = poster.getStatus() + " " + poster.getServerResponse();
}
}

public void libraryEvent(Object library, int event, Object data)
{

}
}

Here is the PHP that this posts to (PHP is not required, any language can be used to receive the standard HTTP file upload that comes from the example):

You can find more examples and a discussion on using this library from my course Mobile Media Week 7 notes

MVideoPlayback Library

I recently needed to develop a library for Mobile Processing for video playback that works with my MVideoCapture library. You can download the library and source.

Here is a quick example for using it (this example also uses my MVideoCapture library):

import processing.core.*;
import com.mobvcasting.mvideocapture.*;
import com.mobvcasting.mvideoplayback.*;

public class MVideoCaptureTest extends PMIDlet
{
MVideoPlayback vidplay;
MVideoCapture vidcap;
byte[] videoData;

String captureKey = "Capture";
String stopCaptureKey = "Stop Capture";
String playKey = "Play Video";

public void setup()
{
softkey(captureKey);

vidcap = new MVideoCapture((PMIDlet)this);
vidcap.showCamera();

noLoop();
}

public void draw()
{
}

public void softkeyPressed(String label)
{
if (label.equals(captureKey))
{
//vidcap.timedCapture(20);
vidcap.startCapture();
softkey(stopCaptureKey);
}
else if (label.equals(stopCaptureKey))
{
vidcap.stopCapture();
}
else if (label.equals(playKey))
{
vidplay = new MVideoPlayback(this,videoData,"video/3gpp");
vidplay.showPlayer(0, 0, width, height);
vidplay.playVideo();
}
redraw();
}

public void libraryEvent(Object library, int event, Object data)
{
if (library.getClass().isInstance(vidcap) && event == MVideoCapture.CAPTURE_COMPLETE)
{
videoData = (byte[])data;
vidcap.hideCamera();
vidcap.closeCamera();

softkey(playKey);
redraw();
}
}
}

You can find more examples and a discussion on using this library from my course Mobile Media Week 7 notes

MVideoCapture Library

I recently needed to develop a library for Mobile Processing for video capture. You can download the library and source.

Here is a quick example for using it (this example also uses my MVideoPlayback library):

import processing.core.*;
import com.mobvcasting.mvideocapture.*;
import com.mobvcasting.mvideoplayback.*;

public class MVideoCaptureTest extends PMIDlet
{
MVideoPlayback vidplay;
MVideoCapture vidcap;
byte[] videoData;

String captureKey = "Capture";
String stopCaptureKey = "Stop Capture";
String playKey = "Play Video";

public void setup()
{
softkey(captureKey);

vidcap = new MVideoCapture((PMIDlet)this);
vidcap.showCamera();

noLoop();
}

public void draw()
{
}

public void softkeyPressed(String label)
{
if (label.equals(captureKey))
{
//vidcap.timedCapture(20);
vidcap.startCapture();
softkey(stopCaptureKey);
}
else if (label.equals(stopCaptureKey))
{
vidcap.stopCapture();
}
else if (label.equals(playKey))
{
vidplay = new MVideoPlayback(this,videoData,"video/3gpp");
vidplay.showPlayer(0, 0, width, height);
vidplay.playVideo();
}
redraw();
}

public void libraryEvent(Object library, int event, Object data)
{
if (library.getClass().isInstance(vidcap) && event == MVideoCapture.CAPTURE_COMPLETE)
{
videoData = (byte[])data;
vidcap.hideCamera();
vidcap.closeCamera();

softkey(playKey);
redraw();
}
}
}

You can find more examples and a discussion on using this library from my course Mobile Media Week 7 notes

MVideoCapture Library – Mobile Processing

UPDATE: An updated post about this library can be found here: http://www.mobvcasting.com/wp/?p=455

I just finished up a library for Mobile Processing called MVideoCapture.

I don’t have time to document it at the moment but you can download, look at the source and try out the following sample code:

import com.mobvcasting.mvideocapture.*;

MVideoCapture vidcap;
byte[] videoData;

String captureKey = "Capture";
String captureStop = "Stop Capture";
String showCamera = "Show Camera";

PFont font;

void setup()
{
softkey(showCamera);
vidcap = new MVideoCapture(this);

font = loadFont("ArialMT-12.mvlw");
textFont(font);
text("Welcome to the test MVideoCapture application",10,15);
noLoop();
}

void draw()
{

}

void softkeyPressed(String label)
{
if (label.equals(captureKey))
{
softkey(captureStop);
vidcap.startCapture();
}
else if (label.equals(captureStop))
{
softkey(captureKey);
vidcap.stopCapture();
}
else if (label.equals(showCamera))
{
softkey(captureKey);
vidcap.showCamera();
}
}

void libraryEvent(Object library, int event, Object data)
{
if (library.getClass().isInstance(vidcap) && event == MVideoCapture.CAPTURE_COMPLETE)
{
videoData = (byte[])data;

saveBytes("savedvideobytes",(byte[])data);

softkey(captureKey);

}
}