Search in sources :

Example 1 with MediaElement

use of org.jivesoftware.smackx.mediaelement.element.MediaElement in project Smack by igniterealtime.

the class MediaElementProvider method parse.

@Override
public MediaElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws IOException, XmlPullParserException, SmackUriSyntaxParsingException {
    UInt16 height = ParserUtils.getUInt16Attribute(parser, "height");
    UInt16 width = ParserUtils.getUInt16Attribute(parser, "width");
    MediaElement.Builder mediaElementBuilder = MediaElement.builder();
    if (height != null && width != null) {
        mediaElementBuilder.setHeightAndWidth(height, width);
    } else if (height != null || width != null) {
        LOGGER.warning("Only one of height and width set while parsing media element");
    }
    outerloop: while (true) {
        XmlPullParser.TagEvent event = parser.nextTag();
        switch(event) {
            case START_ELEMENT:
                QName qname = parser.getQName();
                if (qname.equals(MediaElement.Uri.QNAME)) {
                    MediaElement.Uri uri = parseUri(parser);
                    mediaElementBuilder.addUri(uri);
                }
                break;
            case END_ELEMENT:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
        }
    }
    return mediaElementBuilder.build();
}
Also used : MediaElement(org.jivesoftware.smackx.mediaelement.element.MediaElement) QName(javax.xml.namespace.QName) UInt16(org.jivesoftware.smack.datatypes.UInt16)

Example 2 with MediaElement

use of org.jivesoftware.smackx.mediaelement.element.MediaElement in project Smack by igniterealtime.

the class MediaElementProviderTest method parseMediaElementTest.

@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void parseMediaElementTest(SmackTestUtil.XmlPullParserKind parserKind) throws XmlPullParserException, IOException, SmackParsingException {
    final String xml = "<media xmlns='urn:xmpp:media-element'>" + "<uri type='audio/x-wav'>" + "http://victim.example.com/challenges/speech.wav?F3A6292C" + "</uri>" + "<uri type='audio/ogg; codecs=speex'>" + "cid:sha1+a15a505e360702b79c75a5f67773072ed392f52a@bob.xmpp.org" + "</uri>" + "<uri type='audio/mpeg'>" + "http://victim.example.com/challenges/speech.mp3?F3A6292C" + "</uri>" + "</media>";
    MediaElement mediaElement = SmackTestUtil.parse(xml, MediaElementProvider.class, parserKind);
    List<MediaElement.Uri> uris = mediaElement.getUris();
    assertEquals(3, uris.size());
}
Also used : MediaElement(org.jivesoftware.smackx.mediaelement.element.MediaElement) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with MediaElement

use of org.jivesoftware.smackx.mediaelement.element.MediaElement in project Smack by igniterealtime.

the class MediaElementProviderTest method simpleMediaElementTest.

@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void simpleMediaElementTest(SmackTestUtil.XmlPullParserKind parserKind) throws XmlPullParserException, IOException, SmackParsingException {
    final String xml = "<media xmlns='urn:xmpp:media-element' height='80' width='290'>" + "<uri type='audio/x-wav'>" + "http://victim.example.com/challenges/speech.wav?F3A6292C" + "</uri>" + "</media>";
    MediaElement mediaElement = SmackTestUtil.parse(xml, MediaElementProvider.class, parserKind);
    assertEquals(80, mediaElement.getHeight().intValue());
    assertEquals(290, mediaElement.getWidth().intValue());
    List<MediaElement.Uri> uris = mediaElement.getUris();
    assertEquals(1, uris.size());
    MediaElement.Uri uri = uris.get(0);
    assertEquals("audio/x-wav", uri.getType());
    assertEquals("http://victim.example.com/challenges/speech.wav?F3A6292C", uri.getUri().toString());
}
Also used : MediaElement(org.jivesoftware.smackx.mediaelement.element.MediaElement) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with MediaElement

use of org.jivesoftware.smackx.mediaelement.element.MediaElement in project Smack by igniterealtime.

the class SoftwareInfoManagerTest method buildSoftwareInfoFormUsingBuilder.

public static SoftwareInfoForm buildSoftwareInfoFormUsingBuilder() throws URISyntaxException {
    SoftwareInfoForm.Builder builder = SoftwareInfoForm.getBuilder();
    MediaElement mediaElement = createMediaElement();
    builder.setIcon(mediaElement);
    builder.setOS("Windows");
    builder.setOSVersion("XP");
    builder.setSoftware("Exodus");
    builder.setSoftwareVersion("0.9.1");
    return builder.build();
}
Also used : MediaElement(org.jivesoftware.smackx.mediaelement.element.MediaElement) SoftwareInfoForm(org.jivesoftware.smackx.softwareinfo.form.SoftwareInfoForm)

Example 5 with MediaElement

use of org.jivesoftware.smackx.mediaelement.element.MediaElement in project Smack by igniterealtime.

the class SoftwareInfoForm method getIcon.

/**
 * Returns the software icon if used by client.
 * <br>
 * @return {@link MediaElement} MediaElement or null
 */
public MediaElement getIcon() {
    FormField field = getField(ICON);
    if (field == null) {
        return null;
    }
    FormFieldChildElement media = field.getFormFieldChildElement(MediaElement.QNAME);
    if (media == null) {
        return null;
    }
    return (MediaElement) media;
}
Also used : MediaElement(org.jivesoftware.smackx.mediaelement.element.MediaElement) FormField(org.jivesoftware.smackx.xdata.FormField) TextSingleFormField(org.jivesoftware.smackx.xdata.TextSingleFormField) FormFieldChildElement(org.jivesoftware.smackx.xdata.FormFieldChildElement)

Aggregations

MediaElement (org.jivesoftware.smackx.mediaelement.element.MediaElement)6 SoftwareInfoForm (org.jivesoftware.smackx.softwareinfo.form.SoftwareInfoForm)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 URI (java.net.URI)1 QName (javax.xml.namespace.QName)1 UInt16 (org.jivesoftware.smack.datatypes.UInt16)1 FormField (org.jivesoftware.smackx.xdata.FormField)1 FormFieldChildElement (org.jivesoftware.smackx.xdata.FormFieldChildElement)1 TextSingleFormField (org.jivesoftware.smackx.xdata.TextSingleFormField)1