Player.js 3.8 KB

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