Search in sources :

Example 11 with SMILDocument

use of org.w3c.dom.smil.SMILDocument in project android-aosp-mms by slvn.

the class SmilHelper method getSmilDocument.

/**
 * Parse SMIL message and retrieve SMILDocument.
 *
 * @return A SMILDocument or null if parsing failed.
 */
private static SMILDocument getSmilDocument(PduPart smilPart) {
    try {
        byte[] data = smilPart.getData();
        if (data != null) {
            if (LOCAL_LOGV) {
                Log.v(TAG, "Parsing SMIL document.");
                Log.v(TAG, new String(data));
            }
            ByteArrayInputStream bais = new ByteArrayInputStream(data);
            SMILDocument document = new SmilXmlParser().parse(bais);
            return validate(document);
        }
    } catch (IOException e) {
        Log.e(TAG, "Failed to parse SMIL document.", e);
    } catch (SAXException e) {
        Log.e(TAG, "Failed to parse SMIL document.", e);
    } catch (MmsException e) {
        Log.e(TAG, "Failed to parse SMIL document.", e);
    }
    return null;
}
Also used : MmsException(com.google.android.mms.MmsException) SMILDocument(org.w3c.dom.smil.SMILDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) SmilXmlParser(com.android.mms.dom.smil.parser.SmilXmlParser) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 12 with SMILDocument

use of org.w3c.dom.smil.SMILDocument in project android-aosp-mms by slvn.

the class SmilRegionMediaElementImpl method getRegion.

public SMILRegionElement getRegion() {
    if (mRegion == null) {
        SMILDocument doc = (SMILDocument) this.getOwnerDocument();
        NodeList regions = doc.getLayout().getElementsByTagName("region");
        SMILRegionElement region = null;
        for (int i = 0; i < regions.getLength(); i++) {
            region = (SMILRegionElement) regions.item(i);
            if (region.getId().equals(this.getAttribute("region"))) {
                mRegion = region;
            }
        }
    }
    return mRegion;
}
Also used : SMILDocument(org.w3c.dom.smil.SMILDocument) NodeList(org.w3c.dom.NodeList) SMILRegionElement(org.w3c.dom.smil.SMILRegionElement)

Example 13 with SMILDocument

use of org.w3c.dom.smil.SMILDocument in project android-aosp-mms by slvn.

the class SmilXmlParser method parse.

public SMILDocument parse(InputStream in) throws IOException, SAXException {
    mContentHandler.reset();
    mXmlReader.parse(new InputSource(in));
    SMILDocument doc = mContentHandler.getSmilDocument();
    validateDocument(doc);
    return doc;
}
Also used : InputSource(org.xml.sax.InputSource) SMILDocument(org.w3c.dom.smil.SMILDocument)

Example 14 with SMILDocument

use of org.w3c.dom.smil.SMILDocument in project qksms by moezbhatti.

the class SmilRegionMediaElementImpl method getRegion.

public SMILRegionElement getRegion() {
    if (mRegion == null) {
        SMILDocument doc = (SMILDocument) this.getOwnerDocument();
        NodeList regions = doc.getLayout().getElementsByTagName("region");
        SMILRegionElement region = null;
        for (int i = 0; i < regions.getLength(); i++) {
            region = (SMILRegionElement) regions.item(i);
            if (region.getId().equals(this.getAttribute("region"))) {
                mRegion = region;
            }
        }
    }
    return mRegion;
}
Also used : SMILDocument(org.w3c.dom.smil.SMILDocument) NodeList(org.w3c.dom.NodeList) SMILRegionElement(org.w3c.dom.smil.SMILRegionElement)

Example 15 with SMILDocument

use of org.w3c.dom.smil.SMILDocument in project qksms by moezbhatti.

the class SlideshowModel method createFromPduBody.

public static SlideshowModel createFromPduBody(Context context, PduBody pb) throws MmsException {
    SMILDocument document = SmilHelper.getDocument(pb);
    // Create root-layout model.
    SMILLayoutElement sle = document.getLayout();
    SMILRootLayoutElement srle = sle.getRootLayout();
    int w = srle.getWidth();
    int h = srle.getHeight();
    if ((w == 0) || (h == 0)) {
        w = LayoutManager.getInstance().getLayoutParameters().getWidth();
        h = LayoutManager.getInstance().getLayoutParameters().getHeight();
        srle.setWidth(w);
        srle.setHeight(h);
    }
    RegionModel rootLayout = new RegionModel(null, 0, 0, w, h);
    // Create region models.
    ArrayList<RegionModel> regions = new ArrayList<>();
    NodeList nlRegions = sle.getRegions();
    int regionsNum = nlRegions.getLength();
    for (int i = 0; i < regionsNum; i++) {
        SMILRegionElement sre = (SMILRegionElement) nlRegions.item(i);
        RegionModel r = new RegionModel(sre.getId(), sre.getFit(), sre.getLeft(), sre.getTop(), sre.getWidth(), sre.getHeight(), sre.getBackgroundColor());
        regions.add(r);
    }
    LayoutModel layouts = new LayoutModel(rootLayout, regions);
    // Create slide models.
    SMILElement docBody = document.getBody();
    NodeList slideNodes = docBody.getChildNodes();
    int slidesNum = slideNodes.getLength();
    ArrayList<SlideModel> slides = new ArrayList<>(slidesNum);
    int totalMessageSize = 0;
    for (int i = 0; i < slidesNum; i++) {
        // FIXME: This is NOT compatible with the SMILDocument which is
        // generated by some other mobile phones.
        SMILParElement par = (SMILParElement) slideNodes.item(i);
        // Create media models for each slide.
        NodeList mediaNodes = par.getChildNodes();
        int mediaNum = mediaNodes.getLength();
        ArrayList<MediaModel> mediaSet = new ArrayList<>(mediaNum);
        ArrayList<String> srcs = new ArrayList<>(mediaNum);
        for (int j = 0; j < mediaNum; j++) {
            SMILMediaElement sme = (SMILMediaElement) mediaNodes.item(j);
            srcs.add(sme.getSrc());
        }
        for (int j = 0; j < mediaNum; j++) {
            SMILMediaElement sme = (SMILMediaElement) mediaNodes.item(j);
            try {
                MediaModel media = MediaModelFactory.getMediaModel(context, sme, srcs, layouts, pb);
                /*
                    * This is for slide duration value set.
                    * If mms server does not support slide duration.
                    */
                if (!MmsConfig.getSlideDurationEnabled()) {
                    int mediadur = media.getDuration();
                    float dur = par.getDur();
                    if (dur == 0) {
                        mediadur = MmsConfig.getMinimumSlideElementDuration() * 1000;
                        media.setDuration(mediadur);
                    }
                    if ((int) mediadur / 1000 != dur) {
                        String tag = sme.getTagName();
                        if (ContentType.isVideoType(media.mContentType) || tag.equals(SmilHelper.ELEMENT_TAG_VIDEO) || ContentType.isAudioType(media.mContentType) || tag.equals(SmilHelper.ELEMENT_TAG_AUDIO)) {
                            /*
                                * add 1 sec to release and close audio/video
                                * for guaranteeing the audio/video playing.
                                * because the mmsc does not support the slide duration.
                                */
                            par.setDur((float) mediadur / 1000 + 1);
                        } else {
                            /*
                                * If a slide has an image and an audio/video element
                                * and the audio/video element has longer duration than the image,
                                * The Image disappear before the slide play done. so have to match
                                * an image duration to the slide duration.
                                */
                            if ((int) mediadur / 1000 < dur) {
                                media.setDuration((int) dur * 1000);
                            } else {
                                if ((int) dur != 0) {
                                    media.setDuration((int) dur * 1000);
                                } else {
                                    par.setDur((float) mediadur / 1000);
                                }
                            }
                        }
                    }
                }
                SmilHelper.addMediaElementEventListeners((EventTarget) sme, media);
                mediaSet.add(media);
                totalMessageSize += media.getMediaSize();
            } catch (IOException e) {
                Log.e(TAG, e.getMessage(), e);
            } catch (IllegalArgumentException e) {
                Log.e(TAG, e.getMessage(), e);
            } catch (UnsupportContentTypeException e) {
                Log.e(TAG, e.getMessage(), e);
            }
        }
        SlideModel slide = new SlideModel((int) (par.getDur() * 1000), mediaSet);
        slide.setFill(par.getFill());
        SmilHelper.addParElementEventListeners((EventTarget) par, slide);
        slides.add(slide);
    }
    SlideshowModel slideshow = new SlideshowModel(layouts, slides, document, pb, context);
    slideshow.mTotalMessageSize = totalMessageSize;
    slideshow.registerModelChangedObserver(slideshow);
    return slideshow;
}
Also used : SMILDocument(org.w3c.dom.smil.SMILDocument) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) SMILElement(org.w3c.dom.smil.SMILElement) IOException(java.io.IOException) UnsupportContentTypeException(com.moez.QKSMS.UnsupportContentTypeException) SMILMediaElement(org.w3c.dom.smil.SMILMediaElement) SMILRootLayoutElement(org.w3c.dom.smil.SMILRootLayoutElement) SMILLayoutElement(org.w3c.dom.smil.SMILLayoutElement) SMILParElement(org.w3c.dom.smil.SMILParElement) SMILRegionElement(org.w3c.dom.smil.SMILRegionElement)

Aggregations

SMILDocument (org.w3c.dom.smil.SMILDocument)19 SMILElement (org.w3c.dom.smil.SMILElement)9 SMILParElement (org.w3c.dom.smil.SMILParElement)9 SMILLayoutElement (org.w3c.dom.smil.SMILLayoutElement)8 SMILMediaElement (org.w3c.dom.smil.SMILMediaElement)8 SMILRegionElement (org.w3c.dom.smil.SMILRegionElement)8 NodeList (org.w3c.dom.NodeList)6 SmilDocumentImpl (com.android.mms.dom.smil.SmilDocumentImpl)5 ArrayList (java.util.ArrayList)5 SMILRootLayoutElement (org.w3c.dom.smil.SMILRootLayoutElement)5 IOException (java.io.IOException)4 PduPart (com.google.android.mms.pdu_alt.PduPart)3 SMILRegionMediaElement (org.w3c.dom.smil.SMILRegionMediaElement)3 DrmManagerClient (android.drm.DrmManagerClient)2 SmilXmlParser (com.android.mms.dom.smil.parser.SmilXmlParser)2 MmsException (com.google.android.mms.MmsException)2 PduPart (com.google.android.mms.pdu.PduPart)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputSource (org.xml.sax.InputSource)2