Video.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*!
  2. * Ext JS Library 4.0
  3. * Copyright(c) 2006-2011 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. // From code originally written by David Davis (http://www.sencha.com/blog/html5-video-canvas-and-ext-js/)
  8. /* -NOTICE-
  9. * For HTML5 video to work, your server must
  10. * send the right content type, for more info see:
  11. * http://developer.mozilla.org/En/HTML/Element/Video
  12. */
  13. Ext.define('Ext.ux.desktop.Video', {
  14. extend: 'Ext.panel.Panel',
  15. alias: 'widget.video',
  16. layout: 'fit',
  17. autoplay: false,
  18. controls: true,
  19. bodyStyle: 'background-color:#000;color:#fff',
  20. html: '',
  21. initComponent: function () {
  22. this.callParent();
  23. },
  24. afterRender: function () {
  25. var fallback;
  26. if (this.fallbackHTML) {
  27. fallback = this.fallbackHTML;
  28. } else {
  29. fallback = "Your browser does not support HTML5 Video. ";
  30. if (Ext.isChrome) {
  31. fallback += 'Upgrade Chrome.';
  32. } else if (Ext.isGecko) {
  33. fallback += 'Upgrade to Firefox 3.5 or newer.';
  34. } else {
  35. var chrome = '<a href="http://www.google.com/chrome">Chrome</a>';
  36. fallback += 'Please try <a href="http://www.mozilla.com">Firefox</a>';
  37. if (Ext.isIE) {
  38. fallback += ', ' + chrome +
  39. ' or <a href="http://www.apple.com/safari/">Safari</a>.';
  40. } else {
  41. fallback += ' or ' + chrome + '.';
  42. }
  43. }
  44. }
  45. // match the video size to the panel dimensions
  46. var size = this.getSize();
  47. var cfg = Ext.copyTo({
  48. tag : 'video',
  49. width : size.width,
  50. height: size.height
  51. },
  52. this, 'poster,start,loopstart,loopend,playcount,autobuffer,loop');
  53. // just having the params exist enables them
  54. if (this.autoplay) {
  55. cfg.autoplay = 1;
  56. }
  57. if (this.controls) {
  58. cfg.controls = 1;
  59. }
  60. // handle multiple sources
  61. if (Ext.isArray(this.src)) {
  62. cfg.children = [];
  63. for (var i = 0, len = this.src.length; i < len; i++) {
  64. if (!Ext.isObject(this.src[i])) {
  65. Ext.Error.raise('The src list passed to "video" must be an array of objects');
  66. }
  67. cfg.children.push(
  68. Ext.applyIf({tag: 'source'}, this.src[i])
  69. );
  70. }
  71. cfg.children.push({
  72. html: fallback
  73. });
  74. } else {
  75. cfg.src = this.src;
  76. cfg.html = fallback;
  77. }
  78. this.video = this.body.createChild(cfg);
  79. var el = this.video.dom;
  80. this.supported = (el && el.tagName.toLowerCase() == 'video');
  81. },
  82. afterComponentLayout : function() {
  83. var me = this;
  84. me.callParent(arguments);
  85. if (me.video) {
  86. me.video.setSize(me.body.getSize());
  87. }
  88. },
  89. onDestroy: function () {
  90. var video = this.video;
  91. if (video) {
  92. var videoDom = video.dom;
  93. if (videoDom && videoDom.pause) {
  94. videoDom.pause();
  95. }
  96. video.remove();
  97. this.video = null;
  98. }
  99. this.callParent();
  100. }
  101. });