songinfo.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*---------------------------------------------------
  2. -----------------------------------------------------
  3. Filename: songinfo.m
  4. Version: 1.0
  5. Type: maki
  6. Date: 20. Nov. 2006 - 22:47
  7. Author: Martin Poehlmann aka Deimos
  8. E-Mail: [email protected]
  9. Internet: www.skinconsortium.com
  10. www.martin.deimos.de.vu
  11. -----------------------------------------------------
  12. ---------------------------------------------------*/
  13. #include <lib/std.mi>
  14. Function int getChannels (); // returning 1 for mono, 2 for stereo, more for multichannel (e.g. 6), -1 for no info available
  15. Function string getBitrate();
  16. Function string getFrequency();
  17. Global layer monster;
  18. Global timer delayload, songInfoTimer;
  19. Global Text Bitrate, Frequency;
  20. Global Layer l_Bitrate, l_Frequency;
  21. Global int tempwidth;
  22. Global boolean param;
  23. System.onScriptLoaded()
  24. {
  25. group PlayerDisplay = getScriptgroup();
  26. param = (getParam() == "big");
  27. monster = PlayerDisplay.findObject("monster");
  28. Bitrate = PlayerDisplay.findObject("Bitrate");
  29. Frequency = PlayerDisplay.findObject("Frequency");
  30. l_Bitrate = PlayerDisplay.findObject("Bitrate.label");
  31. l_Frequency = PlayerDisplay.findObject("Frequency.label");
  32. delayload = new Timer;
  33. delayload.setDelay(100);
  34. songInfoTimer = new Timer;
  35. songInfoTimer.setDelay(1000);
  36. Int PlayerStatus = System.getStatus();
  37. if ( PlayerStatus != 0 )
  38. {
  39. delayload.start();
  40. bitrate.setText(getBitrate());
  41. Frequency.setText(getFrequency());
  42. if (PlayerStatus == 1)
  43. {
  44. songInfoTimer.start();
  45. }
  46. }
  47. }
  48. system.onScriptUnloading ()
  49. {
  50. songinfotimer.stop();
  51. delete songinfotimer;
  52. delayload.stop();
  53. delete delayload;
  54. }
  55. System.onResume()
  56. {
  57. delayload.start();
  58. songInfoTimer.start();
  59. }
  60. System.onPlay()
  61. {
  62. delayload.start();
  63. songInfoTimer.start();
  64. }
  65. System.onStop ()
  66. {
  67. monster.setXmlParam("image", "player.songinfo.na");
  68. songInfoTimer.stop();
  69. }
  70. system.onPause ()
  71. {
  72. songInfoTimer.stop();
  73. }
  74. System.onTitleChange(String newtitle)
  75. {
  76. delayload.start();
  77. bitrate.setText(getBitrate());
  78. }
  79. delayload.onTimer ()
  80. {
  81. delayload.stop();
  82. int c = getChannels();
  83. if (c == -1) monster.setXmlParam("image", "player.songinfo.na");
  84. else if (c == 1) monster.setXmlParam("image", "player.songinfo.mono");
  85. else if (c == 2 || c == 3) monster.setXmlParam("image", "player.songinfo.stereo");
  86. else
  87. {
  88. if (tempwidth > 23) monster.setXmlParam("image", "player.songinfo.multi2");
  89. else monster.setXmlParam("image", "player.songinfo.multi");
  90. }
  91. //ensure to display bitrate & frequency
  92. bitrate.setText(getBitrate());
  93. Frequency.setText(getFrequency());
  94. }
  95. Int getChannels ()
  96. {
  97. if (strsearch(getSongInfoText(), "tereo") != -1)
  98. {
  99. return 2;
  100. }
  101. else if (strsearch(getSongInfoText(), "ono") != -1)
  102. {
  103. return 1;
  104. }
  105. else if (strsearch(getSongInfoText(), "annels") != -1)
  106. {
  107. int pos = strsearch(getSongInfoText(), "annels");
  108. return stringToInteger(strmid(getSongInfoText(), pos - 4, 1));
  109. }
  110. else
  111. {
  112. return -1;
  113. }
  114. }
  115. songInfoTimer.onTimer ()
  116. {
  117. bitrate.setText(getBitrate());
  118. }
  119. string getBitrate ()
  120. {
  121. string sit = strlower(getSongInfoText());
  122. if (sit != "")
  123. {
  124. string rtn;
  125. int searchresult;
  126. for (int i = 0; i < 5; i++) {
  127. rtn = getToken(sit, " ", i);
  128. searchResult = strsearch(rtn, "kbps");
  129. if (searchResult>0) return StrMid(rtn, 0, searchResult);
  130. }
  131. return "";
  132. }
  133. else
  134. {
  135. return "";
  136. }
  137. }
  138. string getFrequency ()
  139. {
  140. string sit = strlower(getSongInfoText());
  141. if (sit != "")
  142. {
  143. string rtn;
  144. int searchresult;
  145. for (int i = 0; i < 5; i++) {
  146. rtn = getToken(sit, " ", i);
  147. searchResult = strsearch(strlower(rtn), "khz");
  148. if (searchResult>0)
  149. {
  150. rtn = StrMid(rtn, 0, searchResult);
  151. searchResult = strsearch(strlower(rtn), ".");
  152. if (searchResult>0)
  153. {
  154. rtn = getToken(rtn, ".", 0);
  155. }
  156. return rtn;
  157. }
  158. }
  159. return "";
  160. }
  161. else
  162. {
  163. return "";
  164. }
  165. }
  166. Bitrate.onTextChanged (String newtxt)
  167. {
  168. if (param) return;
  169. if (Bitrate.getTextWidth() == tempwidth) return;
  170. tempwidth = getTextWidth();
  171. if (getTextWidth() > 23)
  172. {
  173. monster.setXmlParam("x", "-39");
  174. Frequency.setXmlParam("x", "-75");
  175. l_Bitrate.setXmlParam("x", "-91");
  176. l_Frequency.setXmlParam("x", "-58");
  177. Bitrate.setXmlParam("w", "26");
  178. if (getChannels() > 3) monster.setXmlParam("image", "player.songinfo.multi2");
  179. }
  180. else
  181. {
  182. monster.setXmlParam("x", "-45");
  183. Frequency.setXmlParam("x", "-80");
  184. l_Bitrate.setXmlParam("x", "-96");
  185. l_Frequency.setXmlParam("x", "-63");
  186. Bitrate.setXmlParam("w", "20");
  187. if (getChannels() > 3) monster.setXmlParam("image", "player.songinfo.multi");
  188. }
  189. }