Search in sources :

Example 1 with Player

use of javax.media.Player in project Spark by igniterealtime.

the class VideoReceiver method controllerUpdate.

/**
 * ControllerListener for the Players.
 */
public synchronized void controllerUpdate(ControllerEvent ce) {
    Player p = (Player) ce.getSourceController();
    if (p == null)
        return;
    // Get this when the internal players are realized.
    if (ce instanceof RealizeCompleteEvent) {
        p.start();
        Component vc = p.getVisualComponent();
        System.out.println("Start1.1" + vc);
        if (null != vc) {
            System.out.println("### visual component is " + vc);
            JFrame aFrame = new JFrame("Video Frame");
            JPanel aPanel = new JPanel();
            aPanel.setBounds(0, 0, 176, 144);
            aPanel.add(vc);
            aFrame.add(aPanel);
            aPanel.setBackground(Color.gray);
            vc.setVisible(true);
            aPanel.setVisible(true);
            aFrame.setVisible(true);
            aFrame.pack();
        }
    }
    if (ce instanceof ControllerErrorEvent) {
        p.removeControllerListener(this);
        System.err.println("Receiver internal error: " + ce);
    }
}
Also used : JPanel(javax.swing.JPanel) Player(javax.media.Player) JFrame(javax.swing.JFrame) ControllerErrorEvent(javax.media.ControllerErrorEvent) RealizeCompleteEvent(javax.media.RealizeCompleteEvent) Component(java.awt.Component)

Example 2 with Player

use of javax.media.Player in project Smack by igniterealtime.

the class AudioReceiver method controllerUpdate.

/**
 * ControllerListener for the Players.
 */
@Override
public synchronized void controllerUpdate(ControllerEvent ce) {
    Player p = (Player) ce.getSourceController();
    if (p == null)
        return;
    // Get this when the internal players are realized.
    if (ce instanceof RealizeCompleteEvent) {
        p.start();
    }
    if (ce instanceof ControllerErrorEvent) {
        p.removeControllerListener(this);
        LOGGER.severe("Receiver internal error: " + ce);
    }
}
Also used : Player(javax.media.Player) ControllerErrorEvent(javax.media.ControllerErrorEvent) RealizeCompleteEvent(javax.media.RealizeCompleteEvent)

Example 3 with Player

use of javax.media.Player in project Smack by igniterealtime.

the class AudioReceiver method update.

/**
 * ReceiveStreamListener.
 */
@Override
public synchronized void update(ReceiveStreamEvent evt) {
    // could be null.
    Participant participant = evt.getParticipant();
    // could be null.
    ReceiveStream stream = evt.getReceiveStream();
    if (evt instanceof RemotePayloadChangeEvent) {
        LOGGER.severe("  - Received an RTP PayloadChangeEvent.");
        LOGGER.severe("Sorry, cannot handle payload change.");
    } else if (evt instanceof NewReceiveStreamEvent) {
        try {
            stream = evt.getReceiveStream();
            DataSource ds = stream.getDataSource();
            // Find out the formats.
            RTPControl ctl = (RTPControl) ds.getControl("javax.jmf.rtp.RTPControl");
            if (ctl != null) {
                LOGGER.severe("  - Received new RTP stream: " + ctl.getFormat());
            } else
                LOGGER.severe("  - Received new RTP stream");
            if (participant == null)
                LOGGER.severe("      The sender of this stream had yet to be identified.");
            else {
                LOGGER.severe("      The stream comes from: " + participant.getCNAME());
            }
            // create a player by passing datasource to the Media Manager
            Player p = javax.media.Manager.createPlayer(ds);
            if (p == null)
                return;
            p.addControllerListener(this);
            p.realize();
            jingleMediaSession.mediaReceived(participant != null ? participant.getCNAME() : "");
            // Notify initialize() that a new stream had arrived.
            synchronized (dataSync) {
                dataReceived = true;
                dataSync.notifyAll();
            }
        } catch (Exception e) {
            LOGGER.severe("NewReceiveStreamEvent exception " + e.getMessage());
            return;
        }
    } else if (evt instanceof StreamMappedEvent) {
        if (stream != null && stream.getDataSource() != null) {
            DataSource ds = stream.getDataSource();
            // Find out the formats.
            RTPControl ctl = (RTPControl) ds.getControl("javax.jmf.rtp.RTPControl");
            LOGGER.severe("  - The previously unidentified stream ");
            if (ctl != null)
                LOGGER.severe("      " + ctl.getFormat());
            LOGGER.severe("      had now been identified as sent by: " + participant.getCNAME());
        }
    } else if (evt instanceof ByeEvent) {
        LOGGER.severe("  - Got \"bye\" from: " + participant.getCNAME());
    }
}
Also used : ByeEvent(javax.media.rtp.event.ByeEvent) Player(javax.media.Player) Participant(javax.media.rtp.Participant) NewReceiveStreamEvent(javax.media.rtp.event.NewReceiveStreamEvent) ReceiveStream(javax.media.rtp.ReceiveStream) RTPControl(javax.media.rtp.RTPControl) RemotePayloadChangeEvent(javax.media.rtp.event.RemotePayloadChangeEvent) StreamMappedEvent(javax.media.rtp.event.StreamMappedEvent) DataSource(javax.media.protocol.DataSource)

Example 4 with Player

use of javax.media.Player in project Spark by igniterealtime.

the class VideoReceiver method update.

/**
 * ReceiveStreamListener
 */
public synchronized void update(ReceiveStreamEvent evt) {
    // could be null.
    Participant participant = evt.getParticipant();
    // could be null.
    ReceiveStream stream = evt.getReceiveStream();
    System.out.println(evt);
    if (evt instanceof RemotePayloadChangeEvent) {
        System.err.println("  - Received an RTP PayloadChangeEvent.");
        System.err.println("Sorry, cannot handle payload change.");
    // System.exit(0);
    } else if (evt instanceof NewReceiveStreamEvent) {
        try {
            stream = ((NewReceiveStreamEvent) evt).getReceiveStream();
            DataSource ds = stream.getDataSource();
            System.out.println("DataSource:" + ds);
            // Find out the formats.
            RTPControl ctl = (RTPControl) ds.getControl("javax.jmf.rtp.RTPControl");
            if (ctl != null) {
                System.err.println("  - Recevied new RTP stream: " + ctl.getFormat());
            } else
                System.err.println("  - Recevied new RTP stream");
            if (participant == null)
                System.err.println("      The sender of this stream had yet to be identified.");
            else {
                System.err.println("      The stream comes from: " + participant.getCNAME());
            }
            // create a player by passing datasource to the Media Manager
            Player p = javax.media.Manager.createPlayer(ds);
            if (p == null)
                return;
            p.addControllerListener(this);
            p.realize();
            // Notify intialize() that a new stream had arrived.
            synchronized (dataSync) {
                dataReceived = true;
                dataSync.notifyAll();
            }
            System.out.println("Start2");
        } catch (Exception e) {
            System.err.println("NewReceiveStreamEvent exception " + e.getMessage());
            return;
        }
    } else if (evt instanceof StreamMappedEvent) {
        if (stream != null && stream.getDataSource() != null) {
            DataSource ds = stream.getDataSource();
            // Find out the formats.
            RTPControl ctl = (RTPControl) ds.getControl("javax.jmf.rtp.RTPControl");
            System.err.println("  - The previously unidentified stream ");
            if (ctl != null)
                System.err.println("      " + ctl.getFormat());
            System.err.println("      had now been identified as sent by: " + participant.getCNAME());
        }
    } else if (evt instanceof ByeEvent) {
        System.err.println("  - Got \"bye\" from: " + participant.getCNAME());
    }
}
Also used : ByeEvent(javax.media.rtp.event.ByeEvent) Player(javax.media.Player) Participant(javax.media.rtp.Participant) NewReceiveStreamEvent(javax.media.rtp.event.NewReceiveStreamEvent) ReceiveStream(javax.media.rtp.ReceiveStream) RTPControl(javax.media.rtp.RTPControl) RemotePayloadChangeEvent(javax.media.rtp.event.RemotePayloadChangeEvent) StreamMappedEvent(javax.media.rtp.event.StreamMappedEvent) DataSource(javax.media.protocol.DataSource)

Aggregations

Player (javax.media.Player)4 ControllerErrorEvent (javax.media.ControllerErrorEvent)2 RealizeCompleteEvent (javax.media.RealizeCompleteEvent)2 DataSource (javax.media.protocol.DataSource)2 Participant (javax.media.rtp.Participant)2 RTPControl (javax.media.rtp.RTPControl)2 ReceiveStream (javax.media.rtp.ReceiveStream)2 ByeEvent (javax.media.rtp.event.ByeEvent)2 NewReceiveStreamEvent (javax.media.rtp.event.NewReceiveStreamEvent)2 RemotePayloadChangeEvent (javax.media.rtp.event.RemotePayloadChangeEvent)2 StreamMappedEvent (javax.media.rtp.event.StreamMappedEvent)2 Component (java.awt.Component)1 JFrame (javax.swing.JFrame)1 JPanel (javax.swing.JPanel)1