public static void main(String[] args) { if (args.length < 2) { System.out.println("Usage: <port> <filename>"); System.exit(0); } int port = Integer.parseInt(args[0]); String filename = args[1]; DataOutputPacketManager dopm = null; IncomingConnection conn = null; try { dopm = new DataOutputPacketManager(filename); conn = new IncomingConnection(port); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); System.exit(99); } System.out.println("Ready to receive"); Packet p; do { p = conn.getNextPacket(); if (p == null) continue; try { System.out.println("Received packet (" + p.getShort(0) + ")"); } catch (PacketException e1) { System.err.println(e1.getMessage()); e1.printStackTrace(); } try { dopm.storePacket(p); } catch (PacketException e) { System.err.println(e.getMessage()); e.printStackTrace(); continue; } } while (!dopm.complete()); System.out.println("Receiver complete"); conn.close(); }
public void onDestroy() { // savePreferences("myPref"); // savePreferences("preferences"); if (!isRecording) { Log.i(TAG, "in onDestroy"); if (conn != null) { try { conn.stop(); } catch (Exception e) { Log.i(TAG, "Error in socket close: " + e.getMessage()); } } stop = true; super.onDestroy(); } }
public void processCommand(Bundle b) { try { short com = b.getShort("command"); byte[] args = b.getByteArray("arguments"); int ch = b.getInt("chan"); if (com == 106) { tmpch = ch; constructorVideo(); start(); // captureButton.performClick(); } else if (com == 107) { stop(); // captureButton.performClick(); } else procCmd.process(com, args, ch); } catch (Exception e) { sendError("Error on Client:" + e.getMessage()); } }
private boolean prepareVideoRecorder() { mMediaRecorder = new MediaRecorder(); // Step 1: Unlock and set camera to MediaRecorder camera.unlock(); mMediaRecorder.setCamera(camera); // Step 2: Set sources mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); // Step 3: Set a CamcorderProfile (requires API Level 8 or higher) // mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH)); // Step 3: Set output format and encoding (for versions prior to API Level 8) mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263); // Step 4: Set output file mMediaRecorder.setOutputFile(ls.getFileDescriptor()); // Step 5: Set the preview output // mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface()); mMediaRecorder.setPreviewDisplay(holder.getSurface()); Log.i(TAG, "Surface valid: " + holder.getSurface().isValid()); /*mMediaRecorder.setVideoSize(176, 144); mMediaRecorder.setVideoFrameRate(20); mMediaRecorder.setAudioChannels(1); */ // Step 6: Prepare configured MediaRecorder try { mMediaRecorder.prepare(); } catch (Exception e) { Log.d(TAG, "Exception preparing MediaRecorder: " + e.getMessage()); releaseMediaRecorder(); return false; } return true; }