Status.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. define("dojox/av/widget/Status", ['dojo', 'dijit', 'dijit/_Widget', 'dijit/_TemplatedMixin'],function(dojo, dijit){
  2. dojo.declare("dojox.av.widget.Status", [dijit._Widget, dijit._TemplatedMixin], {
  3. // summary:
  4. // A Status widget to use with dojox.av.widget.Player
  5. //
  6. // description:
  7. // Displays the name of the media file, and it's current status
  8. // (playing, paused, buffering, etc.) in the middle. Displays
  9. // the playhead time on the left and the duration on the right.
  10. //
  11. templateString: dojo.cache("dojox.av.widget","resources/Status.html"),
  12. setMedia: function(/* Object */med){
  13. // summary:
  14. // A common method to set the media in all Player widgets.
  15. // May do connections and initializations.
  16. //
  17. this.media = med;
  18. dojo.connect(this.media, "onMetaData", this, function(data){
  19. this.duration = data.duration;
  20. this.durNode.innerHTML = this.toSeconds(this.duration);
  21. });
  22. dojo.connect(this.media, "onPosition", this, function(time){
  23. this.timeNode.innerHTML = this.toSeconds(time);
  24. });
  25. var cons = ["onMetaData", "onPosition", "onStart", "onBuffer", "onPlay", "onPaused", "onStop", "onEnd", "onError", "onLoad"];
  26. dojo.forEach(cons, function(c){
  27. dojo.connect(this.media, c, this, c);
  28. }, this);
  29. },
  30. onMetaData: function(data){
  31. this.duration = data.duration;
  32. this.durNode.innerHTML = this.toSeconds(this.duration);
  33. if(this.media.title){
  34. this.title = this.media.title;
  35. }else{
  36. var a = this.media.mediaUrl.split("/");
  37. var b = a[a.length-1].split(".")[0];
  38. this.title = b;
  39. }
  40. },
  41. onBuffer: function(isBuffering){
  42. this.isBuffering = isBuffering;
  43. console.warn("status onBuffer", this.isBuffering);
  44. if(this.isBuffering){
  45. this.setStatus("buffering...");
  46. }else{
  47. this.setStatus("Playing");
  48. }
  49. },
  50. onPosition:function(time){
  51. //console.log("onPosition:", time)
  52. // this.timeNode.innerHTML = this.toSeconds(time);
  53. },
  54. onStart: function(){
  55. this.setStatus("Starting");
  56. },
  57. onPlay: function(){
  58. this.setStatus("Playing");
  59. },
  60. onPaused: function(){
  61. this.setStatus("Paused");
  62. },
  63. onStop: function(){
  64. this.setStatus("Stopped");
  65. },
  66. onEnd: function(){
  67. this.setStatus("Stopped");
  68. },
  69. onError: function(evt){
  70. console.log("status error:", evt)
  71. var msg = evt.info.code;
  72. if(msg == "NetStream.Play.StreamNotFound"){
  73. msg = "Stream Not Found"
  74. }
  75. this.setStatus("ERROR: "+ msg, true);
  76. },
  77. onLoad: function(){
  78. this.setStatus("Loading...");
  79. },
  80. setStatus: function(str, isError){
  81. if(isError){
  82. dojo.addClass(this.titleNode, "statusError");
  83. }else{
  84. dojo.removeClass(this.titleNode, "statusError");
  85. if(this.isBuffering){
  86. str = "buffering...";
  87. }
  88. }
  89. //console.log(this.titleNode, "title:",this.title, "str:",str)
  90. this.titleNode.innerHTML = '<span class="statusTitle">'+this.title+'</span> <span class="statusInfo">'+str+'</span>';
  91. },
  92. toSeconds: function(time){
  93. var ts = time.toString()
  94. if(ts.indexOf(".")<0){
  95. ts += ".00"
  96. }else if(ts.length - ts.indexOf(".")==2){
  97. ts+="0"
  98. }else if(ts.length - ts.indexOf(".")>2){
  99. ts = ts.substring(0, ts.indexOf(".")+3)
  100. }
  101. return ts;
  102. }
  103. });
  104. return dojox.av.widget.Status;
  105. });