Beispiel #1
0
  @Test
  public void setFireGet() throws Exception {

    LastChange lc = new LastChange(new RenderingControlLastChangeParser());

    lc.setEventedValue(0, new RenderingControlVariable.PresetNameList("foo"));
    lc.setEventedValue(0, new RenderingControlVariable.PresetNameList("foobar")); // Double set!

    lc.setEventedValue(
        0, new RenderingControlVariable.Volume(new ChannelVolume(Channel.Master, 123)));

    lc.setEventedValue(
        1, new RenderingControlVariable.Brightness(new UnsignedIntegerTwoBytes(456)));

    final String[] lcValue = new String[1];
    PropertyChangeSupport pcs = new PropertyChangeSupport(this);
    pcs.addPropertyChangeListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            if (ev.getPropertyName().equals("LastChange")) lcValue[0] = (String) ev.getNewValue();
          }
        });
    lc.fire(pcs);

    // Check it's clear
    assertEquals(lc.getEventedValue(0, RenderingControlVariable.PresetNameList.class), null);
    assertEquals(lc.toString(), "");

    // Set something again, it's not fired, so it has no consequence on further assertions
    lc.setEventedValue(0, new RenderingControlVariable.PresetNameList("foo"));

    // Read the XML string instead
    lc = new LastChange(new RenderingControlLastChangeParser(), lcValue[0]);

    assertEquals(
        lc.getEventedValue(0, RenderingControlVariable.PresetNameList.class).getValue(), "foobar");

    assertEquals(
        lc.getEventedValue(0, RenderingControlVariable.Volume.class).getValue().getChannel(),
        Channel.Master);
    assertEquals(
        lc.getEventedValue(0, RenderingControlVariable.Volume.class).getValue().getVolume(),
        new Integer(123));

    assertEquals(
        lc.getEventedValue(1, RenderingControlVariable.Brightness.class).getValue(),
        new UnsignedIntegerTwoBytes(456));
  }
  @Test
  public void lastChangePropagation() throws Exception {

    UnsignedIntegerFourBytes instanceId = new UnsignedIntegerFourBytes(0);

    LastChange avTransportLastChange = new LastChange(new AVTransportLastChangeParser());
    LastChange renderingControlLastChange = new LastChange(new RenderingControlLastChangeParser());

    GstMediaPlayers mps = new GstMediaPlayers(1, avTransportLastChange, renderingControlLastChange);
    GstMediaPlayer mp = mps.get(instanceId);

    assertEquals(mp.getPipeline().getState(), State.NULL);
    assertEquals(mp.isPlaying(), false);

    URI resourceURI =
        Thread.currentThread().getContextClassLoader().getResource("sample.ogv").toURI();
    mp.setURI(resourceURI);
    String lastChangeExpected =
        "<Event xmlns=\"urn:schemas-upnp-org:metadata-1-0/AVT/\">"
            + "<InstanceID val=\"0\">"
            + "<AVTransportURI val=\""
            + resourceURI
            + "\"/>"
            + "<CurrentTrackURI val=\""
            + resourceURI
            + "\"/>"
            + "<TransportState val=\"STOPPED\"/>"
            + "<CurrentTransportActions val=\"Play\"/>"
            + "</InstanceID>"
            + "</Event>";
    assertEquals(avTransportLastChange.toString(), lastChangeExpected);
    avTransportLastChange.reset();

    mp.play();
    Thread.sleep(2000);
    lastChangeExpected =
        "<Event xmlns=\"urn:schemas-upnp-org:metadata-1-0/AVT/\">"
            + "<InstanceID val=\"0\">"
            + "<TransportState val=\"PLAYING\"/>"
            + "<CurrentTransportActions val=\"Stop,Pause,Seek\"/>"
            + "<CurrentTrackDuration val=\"00:00:04\"/>"
            + "<CurrentMediaDuration val=\"00:00:04\"/>"
            + "</InstanceID>"
            + "</Event>";
    assertEquals(avTransportLastChange.toString(), lastChangeExpected);
    avTransportLastChange.reset();

    mp.pause();
    Thread.sleep(500);
    lastChangeExpected =
        "<Event xmlns=\"urn:schemas-upnp-org:metadata-1-0/AVT/\">"
            + "<InstanceID val=\"0\">"
            + "<TransportState val=\"PAUSED_PLAYBACK\"/>"
            + "<CurrentTransportActions val=\"Stop,Pause,Seek,Play\"/>"
            + "</InstanceID>"
            + "</Event>";
    assertEquals(avTransportLastChange.toString(), lastChangeExpected);
    avTransportLastChange.reset();

    mp.play();
    Thread.sleep(500);
    lastChangeExpected =
        "<Event xmlns=\"urn:schemas-upnp-org:metadata-1-0/AVT/\">"
            + "<InstanceID val=\"0\">"
            + "<TransportState val=\"PLAYING\"/>"
            + "<CurrentTransportActions val=\"Stop,Pause,Seek\"/>"
            + "</InstanceID>"
            + "</Event>";
    assertEquals(avTransportLastChange.toString(), lastChangeExpected);
    avTransportLastChange.reset();

    mp.stop();
    Thread.sleep(200);
    lastChangeExpected =
        "<Event xmlns=\"urn:schemas-upnp-org:metadata-1-0/AVT/\">"
            + "<InstanceID val=\"0\">"
            + "<TransportState val=\"STOPPED\"/>"
            + "<CurrentTransportActions val=\"Play\"/>"
            + "</InstanceID>"
            + "</Event>";
    assertEquals(avTransportLastChange.toString(), lastChangeExpected);
    avTransportLastChange.reset();

    mp.play();
    Thread.sleep(500);

    assertEquals(renderingControlLastChange.toString(), "");
    mp.setVolume(0.50);
    Thread.sleep(500);
    lastChangeExpected =
        "<Event xmlns=\"urn:schemas-upnp-org:metadata-1-0/AVT_RCS\">"
            + "<InstanceID val=\"0\">"
            + "<Volume channel=\"Master\" val=\"50\"/>"
            + "</InstanceID>"
            + "</Event>";
    assertEquals(renderingControlLastChange.toString(), lastChangeExpected);
    renderingControlLastChange.reset();

    assertEquals(renderingControlLastChange.toString(), "");
    mp.setMute(true);
    Thread.sleep(500);
    lastChangeExpected =
        "<Event xmlns=\"urn:schemas-upnp-org:metadata-1-0/AVT_RCS\">"
            + "<InstanceID val=\"0\">"
            + "<Volume channel=\"Master\" val=\"0\"/>"
            + "<Mute channel=\"Master\" val=\"1\"/>"
            + "</InstanceID>"
            + "</Event>";
    assertEquals(renderingControlLastChange.toString(), lastChangeExpected);
    renderingControlLastChange.reset();

    assertEquals(renderingControlLastChange.toString(), "");
    mp.setMute(false);
    Thread.sleep(500);
    lastChangeExpected =
        "<Event xmlns=\"urn:schemas-upnp-org:metadata-1-0/AVT_RCS\">"
            + "<InstanceID val=\"0\">"
            + "<Volume channel=\"Master\" val=\"50\"/>"
            + "<Mute channel=\"Master\" val=\"0\"/>"
            + "</InstanceID>"
            + "</Event>";
    assertEquals(renderingControlLastChange.toString(), lastChangeExpected);
    renderingControlLastChange.reset();

    Thread.sleep(3500);
    lastChangeExpected =
        "<Event xmlns=\"urn:schemas-upnp-org:metadata-1-0/AVT/\">"
            + "<InstanceID val=\"0\">"
            + "<TransportState val=\"STOPPED\"/>"
            + "<CurrentTransportActions val=\"Play\"/>"
            + "</InstanceID>"
            + "</Event>";
    assertEquals(avTransportLastChange.toString(), lastChangeExpected);
    avTransportLastChange.reset();
  }