Home | History | Annotate | Download | only in smil
      1 /*
      2  * Copyright (C) 2007-2008 Esmertec AG.
      3  * Copyright (C) 2007-2008 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 package com.android.mms.dom.smil;
     19 
     20 import com.android.mms.dom.events.EventImpl;
     21 import org.w3c.dom.DOMException;
     22 import org.w3c.dom.events.DocumentEvent;
     23 import org.w3c.dom.events.Event;
     24 import org.w3c.dom.smil.ElementTime;
     25 import org.w3c.dom.smil.SMILMediaElement;
     26 import org.w3c.dom.smil.TimeList;
     27 
     28 import android.util.Log;
     29 
     30 public class SmilMediaElementImpl extends SmilElementImpl implements
     31         SMILMediaElement {
     32     public final static String SMIL_MEDIA_START_EVENT = "SmilMediaStart";
     33     public final static String SMIL_MEDIA_END_EVENT = "SmilMediaEnd";
     34     public final static String SMIL_MEDIA_PAUSE_EVENT = "SmilMediaPause";
     35     public final static String SMIL_MEDIA_SEEK_EVENT = "SmilMediaSeek";
     36     private final static String TAG = "Mms:smil";
     37     private static final boolean DEBUG = false;
     38     private static final boolean LOCAL_LOGV = false;
     39 
     40     ElementTime mElementTime = new ElementTimeImpl(this) {
     41             private Event createEvent(String eventType) {
     42                 DocumentEvent doc =
     43                     (DocumentEvent)SmilMediaElementImpl.this.getOwnerDocument();
     44                 Event event = doc.createEvent("Event");
     45                 event.initEvent(eventType, false, false);
     46                 if (LOCAL_LOGV) {
     47                     Log.v(TAG, "Dispatching 'begin' event to "
     48                             + SmilMediaElementImpl.this.getTagName() + " "
     49                             + SmilMediaElementImpl.this.getSrc() + " at "
     50                             + System.currentTimeMillis());
     51                 }
     52                 return event;
     53             }
     54 
     55             private Event createEvent(String eventType, int seekTo) {
     56                 DocumentEvent doc =
     57                     (DocumentEvent)SmilMediaElementImpl.this.getOwnerDocument();
     58                 EventImpl event = (EventImpl) doc.createEvent("Event");
     59                 event.initEvent(eventType, false, false, seekTo);
     60                 if (LOCAL_LOGV) {
     61                     Log.v(TAG, "Dispatching 'begin' event to "
     62                             + SmilMediaElementImpl.this.getTagName() + " "
     63                             + SmilMediaElementImpl.this.getSrc() + " at "
     64                             + System.currentTimeMillis());
     65                 }
     66                 return event;
     67             }
     68 
     69             public boolean beginElement() {
     70                 Event startEvent = createEvent(SMIL_MEDIA_START_EVENT);
     71                 dispatchEvent(startEvent);
     72                 return true;
     73             }
     74 
     75             public boolean endElement() {
     76                 Event endEvent = createEvent(SMIL_MEDIA_END_EVENT);
     77                 dispatchEvent(endEvent);
     78                 return true;
     79             }
     80 
     81             public void resumeElement() {
     82                 Event resumeEvent = createEvent(SMIL_MEDIA_START_EVENT);
     83                 dispatchEvent(resumeEvent);
     84             }
     85 
     86             public void pauseElement() {
     87                 Event pauseEvent = createEvent(SMIL_MEDIA_PAUSE_EVENT);
     88                 dispatchEvent(pauseEvent);
     89             }
     90 
     91             public void seekElement(float seekTo) {
     92                 Event seekEvent = createEvent(SMIL_MEDIA_SEEK_EVENT, (int) seekTo);
     93                 dispatchEvent(seekEvent);
     94             }
     95 
     96             @Override
     97             public float getDur() {
     98                 float dur = super.getDur();
     99                 if (dur == 0) {
    100                     // Duration is not specified, So get the implicit duration.
    101                     String tag = getTagName();
    102                     if (tag.equals("video") || tag.equals("audio")) {
    103                         // Continuous media
    104                         // FIXME Should get the duration of the media. "indefinite" instead here.
    105                         dur = -1.0F;
    106                     } else if (tag.equals("text") || tag.equals("img")) {
    107                         // Discrete media
    108                         dur = 0;
    109                     } else {
    110                         Log.w(TAG, "Unknown media type");
    111                     }
    112                 }
    113                 return dur;
    114             }
    115 
    116             @Override
    117             ElementTime getParentElementTime() {
    118                 return ((SmilParElementImpl) mSmilElement.getParentNode()).mParTimeContainer;
    119             }
    120     };
    121 
    122     /*
    123      * Internal Interface
    124      */
    125 
    126     SmilMediaElementImpl(SmilDocumentImpl owner, String tagName) {
    127         super(owner, tagName);
    128     }
    129 
    130     /*
    131      * SMILMediaElement Interface
    132      */
    133 
    134     public String getAbstractAttr() {
    135         return this.getAttribute("abstract");
    136     }
    137 
    138     public String getAlt() {
    139         return this.getAttribute("alt");
    140     }
    141 
    142     public String getAuthor() {
    143         return this.getAttribute("author");
    144     }
    145 
    146     public String getClipBegin() {
    147         return this.getAttribute("clipBegin");
    148     }
    149 
    150     public String getClipEnd() {
    151         return this.getAttribute("clipEnd");
    152     }
    153 
    154     public String getCopyright() {
    155         return this.getAttribute("copyright");
    156     }
    157 
    158     public String getLongdesc() {
    159         return this.getAttribute("longdesc");
    160     }
    161 
    162     public String getPort() {
    163         return this.getAttribute("port");
    164     }
    165 
    166     public String getReadIndex() {
    167         return this.getAttribute("readIndex");
    168     }
    169 
    170     public String getRtpformat() {
    171         return this.getAttribute("rtpformat");
    172     }
    173 
    174     public String getSrc() {
    175         return this.getAttribute("src");
    176     }
    177 
    178     public String getStripRepeat() {
    179         return this.getAttribute("stripRepeat");
    180     }
    181 
    182     public String getTitle() {
    183         return this.getAttribute("title");
    184     }
    185 
    186     public String getTransport() {
    187         return this.getAttribute("transport");
    188     }
    189 
    190     public String getType() {
    191         return this.getAttribute("type");
    192     }
    193 
    194     public void setAbstractAttr(String abstractAttr) throws DOMException {
    195         this.setAttribute("abstract", abstractAttr);
    196     }
    197 
    198     public void setAlt(String alt) throws DOMException {
    199         this.setAttribute("alt", alt);
    200     }
    201 
    202     public void setAuthor(String author) throws DOMException {
    203         this.setAttribute("author", author);
    204     }
    205 
    206     public void setClipBegin(String clipBegin) throws DOMException {
    207         this.setAttribute("clipBegin", clipBegin);
    208     }
    209 
    210     public void setClipEnd(String clipEnd) throws DOMException {
    211         this.setAttribute("clipEnd", clipEnd);
    212     }
    213 
    214     public void setCopyright(String copyright) throws DOMException {
    215         this.setAttribute("copyright", copyright);
    216     }
    217 
    218     public void setLongdesc(String longdesc) throws DOMException {
    219         this.setAttribute("longdesc", longdesc);
    220 
    221     }
    222 
    223     public void setPort(String port) throws DOMException {
    224         this.setAttribute("port", port);
    225     }
    226 
    227     public void setReadIndex(String readIndex) throws DOMException {
    228         this.setAttribute("readIndex", readIndex);
    229     }
    230 
    231     public void setRtpformat(String rtpformat) throws DOMException {
    232         this.setAttribute("rtpformat", rtpformat);
    233     }
    234 
    235     public void setSrc(String src) throws DOMException {
    236         this.setAttribute("src", src);
    237     }
    238 
    239     public void setStripRepeat(String stripRepeat) throws DOMException {
    240         this.setAttribute("stripRepeat", stripRepeat);
    241     }
    242 
    243     public void setTitle(String title) throws DOMException {
    244         this.setAttribute("title", title);
    245     }
    246 
    247     public void setTransport(String transport) throws DOMException {
    248         this.setAttribute("transport", transport);
    249     }
    250 
    251     public void setType(String type) throws DOMException {
    252         this.setAttribute("type", type);
    253     }
    254 
    255     /*
    256      * TimeElement Interface
    257      */
    258 
    259     public boolean beginElement() {
    260         return mElementTime.beginElement();
    261     }
    262 
    263     public boolean endElement() {
    264         return mElementTime.endElement();
    265     }
    266 
    267     public TimeList getBegin() {
    268         return mElementTime.getBegin();
    269     }
    270 
    271     public float getDur() {
    272         return mElementTime.getDur();
    273     }
    274 
    275     public TimeList getEnd() {
    276         return mElementTime.getEnd();
    277     }
    278 
    279     public short getFill() {
    280         return mElementTime.getFill();
    281     }
    282 
    283     public short getFillDefault() {
    284         return mElementTime.getFillDefault();
    285     }
    286 
    287     public float getRepeatCount() {
    288         return mElementTime.getRepeatCount();
    289     }
    290 
    291     public float getRepeatDur() {
    292         return mElementTime.getRepeatDur();
    293     }
    294 
    295     public short getRestart() {
    296         return mElementTime.getRestart();
    297     }
    298 
    299     public void pauseElement() {
    300         mElementTime.pauseElement();
    301     }
    302 
    303     public void resumeElement() {
    304         mElementTime.resumeElement();
    305     }
    306 
    307     public void seekElement(float seekTo) {
    308         mElementTime.seekElement(seekTo);
    309     }
    310 
    311     public void setBegin(TimeList begin) throws DOMException {
    312         mElementTime.setBegin(begin);
    313     }
    314 
    315     public void setDur(float dur) throws DOMException {
    316         mElementTime.setDur(dur);
    317     }
    318 
    319     public void setEnd(TimeList end) throws DOMException {
    320         mElementTime.setEnd(end);
    321     }
    322 
    323     public void setFill(short fill) throws DOMException {
    324         mElementTime.setFill(fill);
    325     }
    326 
    327     public void setFillDefault(short fillDefault) throws DOMException {
    328         mElementTime.setFillDefault(fillDefault);
    329     }
    330 
    331     public void setRepeatCount(float repeatCount) throws DOMException {
    332         mElementTime.setRepeatCount(repeatCount);
    333     }
    334 
    335     public void setRepeatDur(float repeatDur) throws DOMException {
    336         mElementTime.setRepeatDur(repeatDur);
    337     }
    338 
    339     public void setRestart(short restart) throws DOMException {
    340         mElementTime.setRestart(restart);
    341     }
    342 }
    343