• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
SmilMediaElementImpl(SmilDocumentImpl owner, String tagName)127     SmilMediaElementImpl(SmilDocumentImpl owner, String tagName) {
128         super(owner, tagName);
129     }
130 
131     /*
132      * SMILMediaElement Interface
133      */
134 
getAbstractAttr()135     public String getAbstractAttr() {
136         return this.getAttribute("abstract");
137     }
138 
getAlt()139     public String getAlt() {
140         return this.getAttribute("alt");
141     }
142 
getAuthor()143     public String getAuthor() {
144         return this.getAttribute("author");
145     }
146 
getClipBegin()147     public String getClipBegin() {
148         return this.getAttribute("clipBegin");
149     }
150 
getClipEnd()151     public String getClipEnd() {
152         return this.getAttribute("clipEnd");
153     }
154 
getCopyright()155     public String getCopyright() {
156         return this.getAttribute("copyright");
157     }
158 
getLongdesc()159     public String getLongdesc() {
160         return this.getAttribute("longdesc");
161     }
162 
getPort()163     public String getPort() {
164         return this.getAttribute("port");
165     }
166 
getReadIndex()167     public String getReadIndex() {
168         return this.getAttribute("readIndex");
169     }
170 
getRtpformat()171     public String getRtpformat() {
172         return this.getAttribute("rtpformat");
173     }
174 
getSrc()175     public String getSrc() {
176         return this.getAttribute("src");
177     }
178 
getStripRepeat()179     public String getStripRepeat() {
180         return this.getAttribute("stripRepeat");
181     }
182 
getTitle()183     public String getTitle() {
184         return this.getAttribute("title");
185     }
186 
getTransport()187     public String getTransport() {
188         return this.getAttribute("transport");
189     }
190 
getType()191     public String getType() {
192         return this.getAttribute("type");
193     }
194 
setAbstractAttr(String abstractAttr)195     public void setAbstractAttr(String abstractAttr) throws DOMException {
196         this.setAttribute("abstract", abstractAttr);
197     }
198 
setAlt(String alt)199     public void setAlt(String alt) throws DOMException {
200         this.setAttribute("alt", alt);
201     }
202 
setAuthor(String author)203     public void setAuthor(String author) throws DOMException {
204         this.setAttribute("author", author);
205     }
206 
setClipBegin(String clipBegin)207     public void setClipBegin(String clipBegin) throws DOMException {
208         this.setAttribute("clipBegin", clipBegin);
209     }
210 
setClipEnd(String clipEnd)211     public void setClipEnd(String clipEnd) throws DOMException {
212         this.setAttribute("clipEnd", clipEnd);
213     }
214 
setCopyright(String copyright)215     public void setCopyright(String copyright) throws DOMException {
216         this.setAttribute("copyright", copyright);
217     }
218 
setLongdesc(String longdesc)219     public void setLongdesc(String longdesc) throws DOMException {
220         this.setAttribute("longdesc", longdesc);
221 
222     }
223 
setPort(String port)224     public void setPort(String port) throws DOMException {
225         this.setAttribute("port", port);
226     }
227 
setReadIndex(String readIndex)228     public void setReadIndex(String readIndex) throws DOMException {
229         this.setAttribute("readIndex", readIndex);
230     }
231 
setRtpformat(String rtpformat)232     public void setRtpformat(String rtpformat) throws DOMException {
233         this.setAttribute("rtpformat", rtpformat);
234     }
235 
setSrc(String src)236     public void setSrc(String src) throws DOMException {
237         this.setAttribute("src", src);
238     }
239 
setStripRepeat(String stripRepeat)240     public void setStripRepeat(String stripRepeat) throws DOMException {
241         this.setAttribute("stripRepeat", stripRepeat);
242     }
243 
setTitle(String title)244     public void setTitle(String title) throws DOMException {
245         this.setAttribute("title", title);
246     }
247 
setTransport(String transport)248     public void setTransport(String transport) throws DOMException {
249         this.setAttribute("transport", transport);
250     }
251 
setType(String type)252     public void setType(String type) throws DOMException {
253         this.setAttribute("type", type);
254     }
255 
256     /*
257      * TimeElement Interface
258      */
259 
beginElement()260     public boolean beginElement() {
261         return mElementTime.beginElement();
262     }
263 
endElement()264     public boolean endElement() {
265         return mElementTime.endElement();
266     }
267 
getBegin()268     public TimeList getBegin() {
269         return mElementTime.getBegin();
270     }
271 
getDur()272     public float getDur() {
273         return mElementTime.getDur();
274     }
275 
getEnd()276     public TimeList getEnd() {
277         return mElementTime.getEnd();
278     }
279 
getFill()280     public short getFill() {
281         return mElementTime.getFill();
282     }
283 
getFillDefault()284     public short getFillDefault() {
285         return mElementTime.getFillDefault();
286     }
287 
getRepeatCount()288     public float getRepeatCount() {
289         return mElementTime.getRepeatCount();
290     }
291 
getRepeatDur()292     public float getRepeatDur() {
293         return mElementTime.getRepeatDur();
294     }
295 
getRestart()296     public short getRestart() {
297         return mElementTime.getRestart();
298     }
299 
pauseElement()300     public void pauseElement() {
301         mElementTime.pauseElement();
302     }
303 
resumeElement()304     public void resumeElement() {
305         mElementTime.resumeElement();
306     }
307 
seekElement(float seekTo)308     public void seekElement(float seekTo) {
309         mElementTime.seekElement(seekTo);
310     }
311 
setBegin(TimeList begin)312     public void setBegin(TimeList begin) throws DOMException {
313         mElementTime.setBegin(begin);
314     }
315 
setDur(float dur)316     public void setDur(float dur) throws DOMException {
317         mElementTime.setDur(dur);
318     }
319 
setEnd(TimeList end)320     public void setEnd(TimeList end) throws DOMException {
321         mElementTime.setEnd(end);
322     }
323 
setFill(short fill)324     public void setFill(short fill) throws DOMException {
325         mElementTime.setFill(fill);
326     }
327 
setFillDefault(short fillDefault)328     public void setFillDefault(short fillDefault) throws DOMException {
329         mElementTime.setFillDefault(fillDefault);
330     }
331 
setRepeatCount(float repeatCount)332     public void setRepeatCount(float repeatCount) throws DOMException {
333         mElementTime.setRepeatCount(repeatCount);
334     }
335 
setRepeatDur(float repeatDur)336     public void setRepeatDur(float repeatDur) throws DOMException {
337         mElementTime.setRepeatDur(repeatDur);
338     }
339 
setRestart(short restart)340     public void setRestart(short restart) throws DOMException {
341         mElementTime.setRestart(restart);
342     }
343 }
344