Home | Trees | Indices | Help |
|
---|
|
1 """ 2 * Copyright 2009 Mark Renouf 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License") you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * the License at 7 * 8 * http:#www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHDIR 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 """ 16 17 18 from pyjamas.ui import Event 19 from pyjamas import DOM 20 from pyjamas.ui.Widget import Widget 2123 JS(""" 24 window['console']['log']('mediaEventGetTypeInt: ' + eventType) 25 switch (eventType) { 26 case "abort": return 0x00001; 27 case "canplay": return 0x00002; 28 case "canplaythrough": return 0x00004; 29 case "durationchange": return 0x00008; 30 case "emptied": return 0x00010; 31 case "ended": return 0x00020; 32 case "error": return 0x00040; 33 case "loadstart": return 0x00080; 34 case "loadeddata": return 0x00100; 35 case "loadedmetadata": return 0x00200; 36 case "pause": return 0x00400; 37 case "play": return 0x00800; 38 case "playing": return 0x01000; 39 case "progress": return 0x02000; 40 case "ratechange": return 0x04000; 41 case "seeked": return 0x08000; 42 case "seeking": return 0x10000; 43 case "stalled": return 0x20000; 44 case "suspend": return 0x40000; 45 case "timeupdate": return 0x80000; 46 case "volumechange": return 0x100000; 47 case "waiting": return 0x200000; 48 default: 49 window['console']['debug']("Unknown media eventType: " + eventType) 50 return 0; 51 } 52 """)5355 """ 56 HasAbortHandlers, 57 HasCanPlayHandlers, HasCanPlayThroughHandlers, HasDurationChangeHandlers, 58 HasEmptiedHandlers, 59 HasEndedHandlers, HasErrorHandlers, HasLoadStartHandlers, 60 HasLoadedDataHandlers, HasLoadedMetadataHandlers, HasPauseHandlers, 61 HasPlayHandlers, HasPlayingHandlers, HasProgressHandlers, 62 HasRateChangeHandlers, HasSeekedHandlers, HasSeekingHandlers, 63 HasStalledHandlers, HasSuspendHandlers, HasTimeUpdateHandlers, 64 HasVolumeChangeHandlers, HasWaitingHandlers, HasAllMouseHandlers, 65 HasClickHandlers""" 6664268 self.mediaEventsToSink = 0 69 self.mediaEventsInitialized = False 70 71 Widget.__init__(self, **kwargs)72 7577 s = DOM.createElement("source") 78 DOM.setAttribute(s, 'src', src) 79 DOM.appendChild(self.getElement(), s)80 83 8789 return self.getElement().currentSrc9092 return self.getElement().currentTime9395 self.getElement().currentTime = time9698 return self.getElement().startTime99101 return self.getElement().duration102104 return self.getElement().paused105107 return self.getElement().defaultPlaybackRate108110 self.getElement().defaultPlaybackRate = rate111113 return self.getElement().playbackRate114116 self.getElement().playbackRate = rate117119 return self.getElement().played120122 return self.getElement().seekable123125 return self.getElement().ended126128 return bool(self.getElement().loop)129131 return self.getElement().volume132134 self.getElement().volume = volume135137 return self.getElement().readyState138 139 140 """* 141 * If set, this informs the browser that the media element is likely to be 142 * played and that it should begin buffering the content immediately. 143 * <p> 144 * This setting has no effect if {@linkplain #setAutoplay(boolean) autoplay} 145 * is set. Per the current HTML5 spec, the browser is not required to support 146 * this feature. 147 * 148 * @param autobuffer Whether to begin buffering content immediately 149 """151 self.getElement().autobuffer = autobuffer152 153 154 """* 155 * Whether to automatically begin playback of the media resource as soon as 156 * it's possible to do so without stopping. 157 * 158 * @param autoplay Whether the content should begin playing immediately 159 """161 self.getElement().autoplay = autoplay162 163 164 """* 165 * Whether the media element is to seek back to the start of the media 166 * resource upon reaching the end. 167 * 168 * @param loop whether the media element should loop 169 """171 self.getElement().loop = loop172 173 174 """* 175 * Whether the browser should expose a user interface to the user. This user 176 * interface should include features to begin playback, pause playback, seek 177 * to an arbitrary position in the content (if the content supports arbitrary 178 * seeking), change the volume, and show the media content in manners more 179 * suitable to the user (e.g. full-screen video or in an independent resizable 180 * window). Other controls may also be made available. 181 * 182 * @param controls Whether the browser should show playback controls 183 """ 186 189191 return self.getElement().muted192 195 198 201 204 207 208 209 """* 210 * Adds a handler to be called when the user agent stops fetching the media data before it is 211 * completely downloaded, but not due to an error. 212 """ 213 216 217 218 """* 219 * Adds a handler to be called when the user agent can resume playback of the media data, but 220 * estimates that if playback were to be started now, the media resource could 221 * not be rendered at the current playback rate up to its end without having 222 * to stop for further buffering of content. 223 * 224 * @param handler the {@link CanPlayHandler} to be called 225 """ 226 229 230 231 """* 232 * Adds a handler to be called when the user agent estimates that if playback were to be started 233 * now, the media resource could be rendered at the current playback rate all 234 * the way to its end without having to stop for further buffering. 235 * 236 * @param handler the {@link CanPlayThroughHandler} to be called 237 """ 238 241 242 243 246 247 248 """* 249 * Adds a handler to be called when the duration attribute has just been updated. 250 * 251 * @param handler the {@link DurationChangeHandler} to be called 252 """ 253 256 257 258 """* 259 * Adds a handler to be called when a media element whose networkState was previously not in the 260 * NETWORK_EMPTY state has just switched to that state (either because of a 261 * fatal error during load that's about to be reported, or because the load() 262 * method was invoked while the resource selection algorithm was already 263 * running, in which case it is fired synchronously during the load() method 264 * call). 265 * 266 * @param handler the {@link EmptiedHandler} to be called 267 """ 268 271 272 273 """* 274 * Adds a handler to be called when playback has stopped because the end of the media resource was 275 * reached. 276 * 277 * @param handler the {@link EndedHandler} to be called 278 """ 279 282 283 284 """* 285 * Adds a handler to be called when the user agent begins looking for media data, as part of the 286 * resource selection algorithm. 287 * 288 * @param handler the {@link LoadStartHandler} to be called 289 """ 290 293 294 295 """* 296 * Adds a handler to be called when the user agent can render the media data at the current 297 * playback position for the first time. 298 * 299 * @param handler the {@link LoadedDataHandler} to be called 300 """ 301 304 305 306 """* 307 * Adds a handler to be called when the user agent has just determined the duration and dimensions 308 * of the media resource. 309 * 310 * @param handler the {@link LoadedMetadataHandler} to be called 311 """ 312 315 316 317 """* 318 * Adds a handler to be called when playback has been paused. Fired after the pause method has 319 * returned. 320 * 321 * @param handler the {@link PauseHandler} to be called 322 """ 323 326 327 328 """* 329 * Adds a handler to be called when playback has begun. Fired after the play() method has returned. 330 * 331 * @param handler the {@link PlayHandler} to be called 332 """ 333 336 337 338 """* 339 * Adds a handler to be called when playback has started. 340 * 341 * @param handler the {@link PlayingHandler} to be called 342 """ 343 346 347 348 """* 349 * Adds a handler to be called when the user agent is fetching media data. 350 * 351 * @param handler the {@link ProgressHandler} to be called 352 """ 353 356 357 358 """* 359 * Adds a handler to be called when either the defaultPlaybackRate or the playbackRate attribute 360 * has just been updated. 361 * 362 * @param handler the {@link RateChangeHandler} to be called 363 """ 364 367 368 369 """* 370 * Adds a handler to be called when a seek operation has completed. 371 * 372 * @param handler the {@link SeekedHandler} to be called 373 """ 374 377 378 379 """* 380 * Adds a handler to be called when the user agent is seeking to a time position in the stream. 381 * 382 * @param handler the {@link SeekingHandler} to be called 383 """ 384 387 388 389 """* 390 * Adds a handler to be called when the user agent is trying to fetch media data, but data is 391 * unexpectedly not forthcoming. 392 * 393 * @param handler the {@link StalledHandler} to be called 394 """ 395 398 399 400 """* 401 * Adds a handler to be called when the user agent is intentionally not currently fetching media 402 * data, but does not have the entire media resource downloaded. 403 * 404 * @param handler the {@link SuspendHandler} to be called 405 """ 406 409 410 411 """* 412 * Adds a handler to be called when the current playback position changed as part of normal 413 * playback or in an especially interesting way, for example discontinuously. 414 * 415 * @param handler the {@link TimeUpdateHandler} to be called 416 """ 417 420 421 422 """* 423 * Adds a handler to be called when either the volume attribute or the muted attribute has changed. 424 * Fired after the relevant attribute's setter has returned. 425 * 426 * @param handler the {@link VolumeChangeHandler} to be called 427 """ 428 431 432 433 """* 434 * Adds a handler to be called when playback has stopped because the next frame is not available, 435 * but the user agent expects that frame to become available in due course. 436 * 437 * @param handler the {@link WaitingHandler} to be called 438 """ 439 442 443445 assert handler is not None, "handler must not be None" 446 assert etype is not None, "type must not be None" 447 self.maybeInitMediaEvents() 448 self.sinkMediaEvents(mediaEventGetTypeInt(etype.getName())) 449 return addHandler(handler, etype)450 451 452454 if self.isOrWasAttached(): 455 self.nativeSinkMediaEvents(self.getElement(), eventBitsToAdd) 456 else: 457 self.mediaEventsToSink |= eventBitsToAdd458 459 460 461 """* 462 * doAttachChildren is called immediately after sinkEvents is called in 463 * Widget. This opportunity is taken to lazily attach event handlers to the 464 * element. 465 """467 bitsToAdd = self.mediaEventsToSink 468 self.mediaEventsToSink = -1 469 if bitsToAdd > 0: 470 self.nativeSinkMediaEvents(self.getElement(), bitsToAdd)471 472474 # chMask = (elem.__mediaEventBits or 0) ^ bits 475 # elem.__mediaEventBits = bits; 476 # if not chMask: 477 # return 478 # 479 # if (chMask & 0x00001) and (bits & 0x00001): 480 # elem.addEventListener('abort', mediaDispatchEvent, false) 481 # else: 482 # elem.removeEventListener('abort', mediaDispatchEvent, false) 483 # if (chMask & 0x00002) and (bits & 0x00002): 484 # elem.addEventListener('canplay', mediaDispatchEvent, false) 485 # else: 486 # elem.removeEventListener('canplay', mediaDispatchEvent, false) 487 # if (chMask & 0x00004) and (bits & 0x00004): 488 # elem.addEventListener('canplaythrough', mediaDispatchEvent, false) 489 # else: 490 # elem.removeEventListener('canplaythrough', mediaDispatchEvent, false) 491 # if (chMask & 0x00008) and (bits & 0x00008): 492 # elem.addEventListener('durationchange', mediaDispatchEvent, false) 493 # else: 494 # elem.removeEventListener('durationchange', mediaDispatchEvent, false) 495 # if (chMask & 0x00010) and (bits & 0x00010): 496 # elem.addEventListener('emptied', mediaDispatchEvent, false) 497 # else: 498 # elem.removeEventListener('emptied', mediaDispatchEvent, false) 499 # if (chMask & 0x00020) and (bits & 0x00020): 500 # elem.addEventListener('ended', mediaDispatchEvent, false) 501 # else: 502 # elem.removeEventListener('ended', mediaDispatchEvent, false) 503 # if (chMask & 0x00040) and (bits & 0x00040): 504 # elem.addEventListener('error', mediaDispatchEvent, false) 505 # else: 506 # elem.removeEventListener('error', mediaDispatchEvent, false) 507 # if (chMask & 0x00080) and (bits & 0x00080): 508 # elem.addEventListener('loadstart', mediaDispatchEvent, false) 509 # else: 510 # elem.removeEventListener('loadstart', mediaDispatchEvent, false) 511 # if (chMask & 0x00100) and (bits & 0x00100): 512 # elem.addEventListener('loadeddata', mediaDispatchEvent, false) 513 # else: 514 # elem.removeEventListener('loadeddata', mediaDispatchEvent, false) 515 # if (chMask & 0x00200) and (bits & 0x00200): 516 # elem.addEventListener('loadedmetadata', mediaDispatchEvent, false) 517 # else: 518 # elem.removeEventListener('loadedmetadata', mediaDispatchEvent, false) 519 # if (chMask & 0x00400) and (bits & 0x00400): 520 # elem.addEventListener('pause', mediaDispatchEvent, false) 521 # else: 522 # elem.removeEventListener('pause', mediaDispatchEvent, false) 523 # if (chMask & 0x00800) and (bits & 0x00800): 524 # elem.addEventListener('play', mediaDispatchEvent, false) 525 # else: 526 # elem.removeEventListener('play', mediaDispatchEvent, false) 527 # if (chMask & 0x01000) and (bits & 0x01000): 528 # elem.addEventListener('playing', mediaDispatchEvent, false) 529 # else: 530 # elem.removeEventListener('playing', mediaDispatchEvent, false) 531 # if (chMask & 0x02000) and (bits & 0x02000): 532 # elem.addEventListener('progress', mediaDispatchEvent, false) 533 # else: 534 # elem.removeEventListener('progress', mediaDispatchEvent, false) 535 # if (chMask & 0x04000) and (bits & 0x04000): 536 # elem.addEventListener('ratechange', mediaDispatchEvent, false) 537 # else: 538 # elem.removeEventListener('ratechange', mediaDispatchEvent, false) 539 # if (chMask & 0x08000) and (bits & 0x08000): 540 # elem.addEventListener('seeked', mediaDispatchEvent, false) 541 # else: 542 # elem.removeEventListener('seeked', mediaDispatchEvent, false) 543 # if (chMask & 0x10000) and (bits & 0x10000): 544 # elem.addEventListener('seeking', mediaDispatchEvent, false) 545 # else: 546 # elem.removeEventListener('seeking', mediaDispatchEvent, false) 547 # if (chMask & 0x20000) and (bits & 0x20000): 548 # elem.addEventListener('stalled', mediaDispatchEvent, false) 549 # else: 550 # elem.removeEventListener('stalled', mediaDispatchEvent, false) 551 # if (chMask & 0x40000) and (bits & 0x40000): 552 # elem.addEventListener('suspend', mediaDispatchEvent, false) 553 # else: 554 # elem.removeEventListener('suspend', mediaDispatchEvent, false) 555 # if (chMask & 0x80000) and (bits & 0x80000): 556 # elem.addEventListener('timeupdate', mediaDispatchEvent, false) 557 # else: 558 # elem.removeEventListener('timeupdate', mediaDispatchEvent, false) 559 # if (chMask & 0x100000) and (bits & 0x100000): 560 # elem.addEventListener('volumechange', mediaDispatchEvent, false) 561 # else: 562 # elem.removeEventListener('volumechange', mediaDispatchEvent, false) 563 # if (chMask & 0x200000) and (bits & 0x200000): 564 # elem.addEventListener('waiting', mediaDispatchEvent, false) 565 # else: 566 # elem.removeEventListener('waiting', mediaDispatchEvent, false) 567 return568570 return addDomHandler(handler, MouseDownEvent.getType())571 572 573575 return addDomHandler(handler, MouseUpEvent.getType())576 577 578580 return addDomHandler(handler, MouseOutEvent.getType())581 582 583585 return addDomHandler(handler, MouseOverEvent.getType())586 587 588590 return addDomHandler(handler, MouseMoveEvent.getType())591 592 593595 return addDomHandler(handler, MouseWheelEvent.getType())596 597 598600 return addDomHandler(handler, ClickEvent.getType())601 602 607 608 609 610 """* 611 * Warning: W3C/Standards version 612 """614 JS(""" 615 mediaDispatchEvent = function(evt) { 616 var curElem = evt['target']; 617 var listener = curElem['__listener']; 618 if (listener) { 619 @{{self['dispatchMediaEvent']}}(evt, listener) 620 } 621 } 622 """)623 624 625 """* 626 * Dispatches an event to the listener. This bypasses the main GWT event 627 * handling system because it's not possible to access from external packages. 628 * <p> 629 * Due to this event catpure and event preview will not work properly for 630 * media-specific events (existing GWT handled events are not affected). Also, 631 * since the sinkEvents system is not extensible media events can only be 632 * listened for directly on the Media object generating them ie. they will not 633 * be received or handled by any containing elements because these objects 634 * won't know how to set the correct event listeners. 635 * 636 * @param evt 637 * @param listener 638 """
Home | Trees | Indices | Help |
|
---|
http://epydoc.sourceforge.net |