Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
- package org.jitsi.impl.neomedia.device;
- import java.io.File;
- import java.net.MalformedURLException;
- import java.util.Vector;
- import java.util.logging.Level;
- import javax.media.*;
- import javax.media.control.*;
- import javax.media.format.*;
- import javax.media.protocol.ContentDescriptor;
- import javax.media.protocol.DataSource;
- import javax.media.protocol.FileTypeDescriptor;
- import org.jitsi.impl.neomedia.audiolevel.*;
- import org.jitsi.service.neomedia.event.*;
- import org.jitsi.util.*;
- /**
- * Extends <tt>AudioMediaDeviceSession</tt> to add file-recording functionality.
- */
- public class FileMediaDeviceSession extends AudioMediaDeviceSession {
- /**
- * The <tt>Logger</tt> used by the <tt>AudioMediaDeviceSession</tt> class
- * and its instances for logging output.
- */
- private static final Logger logger = Logger
- .getLogger(FileMediaDeviceSession.class);
- /**
- * Initializes a new <tt>MediaDeviceSession</tt> instance which is to
- * represent the use of a specific <tt>MediaDevice</tt> by a
- * <tt>MediaStream</tt>.
- *
- * @param device
- * the <tt>MediaDevice</tt> the use of which by a
- * <tt>MediaStream</tt> is to be represented by the new instance
- */
- protected FileMediaDeviceSession(AbstractMediaDevice device) {
- super(device);
- }
- DataSink sink;
- @Override
- protected void playerControllerUpdate(ControllerEvent event) {
- if (event instanceof ConfigureCompleteEvent) {
- Processor player = (Processor) event.getSourceController();
- if (player != null) {
- // playerConfigureComplete(player);
- // * To use the processor as a Player we must set its
- // * ContentDescriptor to null.
- try {
- // player.setContentDescriptor(null);
- player.setContentDescriptor( new ContentDescriptor(FileTypeDescriptor.WAVE));
- } catch (NotConfiguredError nce) {
- logger.error("Failed to set ContentDescriptor to Player.",
- nce);
- return;
- }
- player.realize();
- }
- } else if (event instanceof RealizeCompleteEvent) {
- Processor player = (Processor) event.getSourceController();
- if (player != null) {
- playerRealizeComplete(player);
- MediaLocator dest = null;
- try {
- dest = new MediaLocator(new File("recording.wav").toURI().toURL());
- } catch (MalformedURLException e1) {
- e1.printStackTrace();
- }
- System.out.println("Trying to record.");
- try {
- sink = Manager.createDataSink(player.getDataOutput(), dest);
- sink.open();
- sink.start();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
- @Override
- protected void disposePlayer(Player player){
- super.disposePlayer(player);
- System.out.println("disposePlayer");
- sink.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement