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