Player.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.av.widget.Player"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.av.widget.Player"] = true;
  8. dojo.provide("dojox.av.widget.Player");
  9. dojo.require("dijit._Widget");
  10. dojo.require("dijit._Templated");
  11. dojo.declare("dojox.av.widget.Player", [dijit._Widget, dijit._Templated], {
  12. // summary:
  13. // A Media Player UI widget for all types of dojox.av and AIR media.
  14. //
  15. // description:
  16. // Currently for markup only. All controls should reside as child
  17. // nodes within the Player node. 'controlType' is used to determine
  18. // the placement of the control. If no type or an unrecoginized type
  19. // is used, it will be left-aligned in the same row as the volume.
  20. // Note:
  21. // Be sure to use 'controlType' as a node attribute. It is not a
  22. // property of the widget.
  23. //
  24. // example:
  25. // | <div dojoType="dojox.av.widget.Player" playerWidth="100%">
  26. // | <div controlType="video" initialVolume=".1"
  27. // | mediaUrl="video/Grog.flv" autoPlay="true"
  28. // | isDebug="false" dojoType="dojox.av.FLVideo"></div>
  29. // | <div controlType="play" dojoType="dojox.av.widget.PlayButton"></div>
  30. // | <div controlType="volume" dojoType="dojox.av.widget.VolumeButton"></div>
  31. // | <div controlType="progress" dojoType="dojox.av.widget.ProgressSlider"></div>
  32. // | <div controlType="status" dojoType="dojox.av.widget.Status"></div>
  33. // | </div>
  34. //
  35. // playerWidth: /* Number or String */
  36. // Sets the width of the player (not the video size)
  37. // Number will be converted to pixels
  38. // String will be used literally. EX: "320px" or "100%"
  39. playerWidth: "480px",
  40. //
  41. // TODO:
  42. //playerHeight
  43. //videoWidth: 320,
  44. //videoHeight: 240,
  45. widgetsInTemplate:true,
  46. templateString: dojo.cache("dojox.av.widget", "resources/Player.html", "<div class=\"playerContainer\">\n\t<div class=\"PlayerScreen\" dojoAttachPoint=\"playerScreen\"></div>\n\t<table class=\"Controls\">\n\t\t<tr>\n\t\t\t<td colspan=\"2\" dojoAttachPoint=\"progressContainer\"></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td class=\"PlayContainer\" dojoAttachPoint=\"playContainer\"></td>\n\t\t\t<td class=\"ControlsRight\">\n\t\t\t<table class=\"StatusContainer\">\n\t\t\t\t<tr dojoAttachPoint=\"statusContainer\">\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan=\"3\" class=\"ControlsBottom\" dojoAttachPoint=\"controlsBottom\"></td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t</td>\n\t\t</tr>\n\t</table>\n</div>\n"),
  47. _fillContent: function(){
  48. // summary
  49. // Finding and collecting child nodes
  50. if(!this.items && this.srcNodeRef){
  51. this.items = [];
  52. var nodes = dojo.query("*", this.srcNodeRef);
  53. dojo.forEach(nodes, function(n){
  54. this.items.push(n);
  55. }, this);
  56. }
  57. },
  58. postCreate: function(){
  59. // summary:
  60. // Do player styling, and place child widgets in the proper location.
  61. //
  62. dojo.style(this.domNode, "width", this.playerWidth+(dojo.isString(this.playerWidth)?"":"px"));
  63. if(dojo.isString(this.playerWidth) && this.playerWidth.indexOf("%")){
  64. dojo.connect(window, "resize", this, "onResize");
  65. }
  66. this.children = [];
  67. var domNode;
  68. dojo.forEach(this.items, function(n, i){
  69. n.id = dijit.getUniqueId("player_control");
  70. switch(dojo.attr(n, "controlType")){
  71. case "play":
  72. this.playContainer.appendChild(n); break;
  73. case "volume" :
  74. this.controlsBottom.appendChild(n); break;
  75. case "status" :
  76. this.statusContainer.appendChild(n); break;
  77. case "progress":
  78. case "slider":
  79. this.progressContainer.appendChild(n); break;
  80. case "video":
  81. this.mediaNode = n;
  82. this.playerScreen.appendChild(n); break;
  83. default:
  84. }
  85. this.items[i] = n.id;
  86. }, this);
  87. },
  88. startup: function(){
  89. // summary:
  90. // Fired when all children are ready. Set the media in
  91. // all children with setMedia()
  92. //
  93. this.media = dijit.byId(this.mediaNode.id);
  94. if(!dojo.isAIR){
  95. dojo.style(this.media.domNode, "width", "100%");
  96. dojo.style(this.media.domNode, "height", "100%");
  97. }
  98. dojo.forEach(this.items, function(id){
  99. if(id !== this.mediaNode.id){
  100. var child = dijit.byId(id);
  101. this.children.push(child);
  102. if(child){
  103. child.setMedia(this.media, this);
  104. }
  105. }
  106. }, this);
  107. },
  108. onResize: function(evt){
  109. // summary:
  110. // If a player size is a percentage, this will fire an onResize
  111. // event for all children, passing the size of the player.
  112. //
  113. var dim = dojo.marginBox(this.domNode);
  114. if(this.media && this.media.onResize !== null){
  115. this.media.onResize(dim);
  116. }
  117. dojo.forEach(this.children, function(child){
  118. if(child.onResize){
  119. child.onResize(dim);
  120. }
  121. });
  122. }
  123. });
  124. }