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();
}
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());
}
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());
}
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();
}
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;
}
Aggregations