Search in sources :

Example 11 with Time

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

the class MediaModelFactory method getGenericMediaModel.

private static MediaModel getGenericMediaModel(Context context, String tag, String src, SMILMediaElement sme, PduPart part, RegionModel regionModel) throws IOException, MmsException {
    byte[] bytes = part.getContentType();
    if (bytes == null) {
        throw new IllegalArgumentException("Content-Type of the part may not be null.");
    }
    String contentType = new String(bytes);
    MediaModel media;
    switch(tag) {
        case SmilHelper.ELEMENT_TAG_TEXT:
            media = new TextModel(context, contentType, src, part.getCharset(), part.getData(), regionModel);
            break;
        case SmilHelper.ELEMENT_TAG_IMAGE:
            media = new ImageModel(context, contentType, src, part.getDataUri(), regionModel);
            break;
        case SmilHelper.ELEMENT_TAG_VIDEO:
            media = new VideoModel(context, contentType, src, part.getDataUri(), regionModel);
            break;
        case SmilHelper.ELEMENT_TAG_AUDIO:
            media = new AudioModel(context, contentType, src, part.getDataUri());
            break;
        case SmilHelper.ELEMENT_TAG_REF:
            if (ContentType.isTextType(contentType)) {
                media = new TextModel(context, contentType, src, part.getCharset(), part.getData(), regionModel);
            } else if (ContentType.isImageType(contentType)) {
                media = new ImageModel(context, contentType, src, part.getDataUri(), regionModel);
            } else if (ContentType.isVideoType(contentType)) {
                media = new VideoModel(context, contentType, src, part.getDataUri(), regionModel);
            } else if (ContentType.isAudioType(contentType)) {
                media = new AudioModel(context, contentType, src, part.getDataUri());
            } else {
                Log.d(TAG, "[MediaModelFactory] getGenericMediaModel Unsupported Content-Type: " + contentType);
                media = createEmptyTextModel(context, regionModel);
            }
            break;
        default:
            throw new IllegalArgumentException("Unsupported TAG: " + tag);
    }
    // Set 'begin' property.
    int begin = 0;
    TimeList tl = sme.getBegin();
    if ((tl != null) && (tl.getLength() > 0)) {
        // We only support a single begin value.
        Time t = tl.item(0);
        begin = (int) (t.getResolvedOffset() * 1000);
    }
    media.setBegin(begin);
    // Set 'duration' property.
    int duration = (int) (sme.getDur() * 1000);
    if (duration <= 0) {
        tl = sme.getEnd();
        if ((tl != null) && (tl.getLength() > 0)) {
            // We only support a single end value.
            Time t = tl.item(0);
            if (t.getTimeType() != Time.SMIL_TIME_INDEFINITE) {
                duration = (int) (t.getResolvedOffset() * 1000) - begin;
                if (duration == 0 && (media instanceof AudioModel || media instanceof VideoModel)) {
                    duration = MmsConfig.getMinimumSlideElementDuration();
                    if (Log.isLoggable(TAG, Log.VERBOSE)) {
                        Log.v(TAG, "[MediaModelFactory] compute new duration for " + tag + ", duration=" + duration);
                    }
                }
            }
        }
    }
    media.setDuration(duration);
    if (!MmsConfig.getSlideDurationEnabled()) {
        /**
         * Because The slide duration is not supported by mmsc,
         * the device has to set fill type as FILL_FREEZE.
         * If not, the media will disappear while rotating the screen
         * in the slide show play view.
         */
        media.setFill(SMILMediaElement.FILL_FREEZE);
    } else {
        // Set 'fill' property.
        media.setFill(sme.getFill());
    }
    return media;
}
Also used : Time(org.w3c.dom.smil.Time) TimeList(org.w3c.dom.smil.TimeList)

Aggregations

Time (org.w3c.dom.smil.Time)11 TimeList (org.w3c.dom.smil.TimeList)11 ElementTime (org.w3c.dom.smil.ElementTime)10 ArrayList (java.util.ArrayList)6 NodeList (org.w3c.dom.NodeList)6 Node (org.w3c.dom.Node)2 NodeListImpl (com.android.mms.dom.NodeListImpl)1 NodeListImpl (org.thoughtcrime.securesms.dom.NodeListImpl)1