Цитата | Как я понял, это сохраняется в файловую систему телефона. А jsr-75 для этого не нужен? |
jsr-75 обязательно нужен, без него нельзя записать в файловую систему. Однако, обычно, где есть камера (Mobile Media API), там есть и jsr-75.
Вот еще примерчик:
Код | import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream;
import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Item; import javax.microedition.lcdui.List; import javax.microedition.media.Manager; import javax.microedition.media.Player; import javax.microedition.media.control.RecordControl; import javax.microedition.media.control.VideoControl; import javax.microedition.midlet.MIDlet;
/** * @author javaitek * */ public class VideoCam extends MIDlet implements CommandListener {
Display display; Form form = new Form("Video"); Command exit = new Command("Выход", Command.EXIT, 1); Command start = new Command("Начать", Command.ITEM, 1); Command stop = new Command("Остановить", Command.ITEM, 1);
String url; Player player; VideoControl videoControl; Item videoItem; RecordControl recordControl; String contentType; ByteArrayOutputStream outputStream;
public VideoCam() { display = Display.getDisplay(this); form.addCommand(exit); form.addCommand(start); form.setCommandListener(this); List list = new List("Тип записи", List.EXCLUSIVE); list.append("video", null); list.append("audio", null); list.addCommand(new Command("Выбрать", Command.ITEM, 1)); list.setCommandListener(new CommandListener() { public void commandAction(Command c, Displayable d) { List list = (List) d; switch (list.getSelectedIndex()) { case 0: url = "capture://video"; break; case 1: url = "capture://audio"; break; default: url = "capture://video"; break; } form.append(url + "\n"); display.setCurrent(form); } }); display.setCurrent(list); }
public void startApp() {}
public void pauseApp() {}
public void destroyApp(boolean unconditional) { notifyDestroyed(); }
public void commandAction(Command c, Displayable d) { if (c == exit) { notifyDestroyed(); } if (c == start) { new Thread() { public void run() { try { form.removeCommand(start); form.addCommand(stop); player = Manager.createPlayer(url); player.realize(); contentType = player.getContentType(); form.append(contentType + "\n"); videoControl = (VideoControl) player.getControl("VideoControl"); if (videoControl != null) { videoItem = (Item) videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null); form.append(videoItem); } else { form.append("No VideoControl" + "\n"); } recordControl = (RecordControl) player.getControl("RecordControl"); if (recordControl != null) { outputStream = new ByteArrayOutputStream(); recordControl.setRecordStream(outputStream); recordControl.startRecord(); form.append("Recording..." + "\n"); } else { form.append("No RecordControl" + "\n"); } player.start(); } catch (Exception e) { e.printStackTrace(); form.append(e.toString() + "\n"); } } }.start(); } if (c == stop) { new Thread() { public void run() { try { form.removeCommand(stop); player.stop(); if (recordControl != null) { recordControl.stopRecord(); recordControl.commit(); form.append("Stopped" + "\n"); } if (videoItem != null) { for (int i = 0; i < form.size(); i++) { Item item = form.get(i); if (item == videoItem) { form.delete(i); } } } if (outputStream != null) { InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); player = Manager.createPlayer(inputStream, contentType); player.realize(); videoControl = (VideoControl) player.getControl("VideoControl"); if (videoControl != null) { videoItem = (Item) videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null); form.append(videoItem); } player.start(); } } catch (Exception e) { e.printStackTrace(); form.append(e.toString() + "\n"); } } }.start(); } }
}
|
В архиве исходник и готовая прога |