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