PageRenderTime 25ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/obsolete/flash/Bitboy/src/de/popforge/widget/bitboy/Display.as

http://popforge.googlecode.com/
ActionScript | 131 lines | 104 code | 27 blank | 0 comment | 5 complexity | 3d3f4629545163909865db9c03a11808 MD5 | raw file
  1. package de.popforge.widget.bitboy
  2. {
  3. import de.popforge.audio.processor.bitboy.BitBoy;
  4. import de.popforge.audio.processor.bitboy.formats.FormatBase;
  5. import flash.display.Sprite;
  6. import flash.events.ProgressEvent;
  7. import flash.events.TimerEvent;
  8. import flash.net.URLLoader;
  9. import flash.text.TextField;
  10. import flash.text.TextFieldAutoSize;
  11. import flash.text.TextFormat;
  12. import flash.utils.Timer;
  13. public class Display extends Sprite
  14. {
  15. private var bitboy: BitBoy;
  16. private var textfield: TextField;
  17. private var textformat: TextFormat;
  18. private var song: SongItem;
  19. private var songNo: String;
  20. private var songInfo: String;
  21. private var songCredits: Array; //-- mostly written in the sample name definition
  22. private var infoTimer: Timer;
  23. private var infoIndex: int;
  24. public function Display( bitboy: BitBoy )
  25. {
  26. this.bitboy = bitboy;
  27. init();
  28. }
  29. public function updateSong( song: SongItem ): void
  30. {
  31. songNo = new String( '0' + ( song.getId() + 1 ) ).substr( -2 );
  32. infoTimer.stop();
  33. this.song = song;
  34. }
  35. public function showPlayListSongInfo(): void
  36. {
  37. var format: FormatBase = song.getFormat();
  38. var length: int = bitboy.getLengthSeconds();
  39. var duration: String;
  40. if( length == -1 )
  41. {
  42. duration = 'loop';
  43. }
  44. else
  45. {
  46. var mm: int = length / 60;
  47. var ss: int = length - mm * 60;
  48. duration = ( mm < 10 ? '0' + mm : mm ) + ':' + ( ss < 10 ? '0' + ss : ss );
  49. }
  50. songCredits = [ format.title + ' (' + duration + ')' ].concat( format.credits );
  51. infoIndex = 0;
  52. textfield.text = songNo + ': ' + songCredits[ infoIndex ];
  53. if( song.hasCredits )
  54. {
  55. infoTimer.reset();
  56. infoTimer.start();
  57. }
  58. }
  59. public function showPlayListSongError( msg: String ): void
  60. {
  61. textfield.text = songNo + ': ' + '#error: ' + msg;
  62. }
  63. public function showError( msg: String ): void
  64. {
  65. textfield.text = '#error: ' + msg;
  66. }
  67. public function showPreloadingInformation( loader: URLLoader ): void
  68. {
  69. loader.addEventListener( ProgressEvent.PROGRESS, onPreloaderProcess );
  70. }
  71. private function onPreloaderProcess( event: ProgressEvent ): void
  72. {
  73. if( event.bytesLoaded < event.bytesTotal )
  74. {
  75. textfield.text = songNo + ': ' + new String( '0' + int( event.bytesLoaded / event.bytesTotal * 100 ) ).substr( -2 ) + '%';
  76. }
  77. else
  78. {
  79. URLLoader( event.target ).removeEventListener( ProgressEvent.PROGRESS, onPreloaderProcess );
  80. }
  81. }
  82. private function init(): void
  83. {
  84. textformat = new TextFormat();
  85. textformat.font = BitboyPlayer.FONT_NAME;
  86. textformat.size = 8;
  87. textformat.color = 0x0000ff;
  88. textfield = new TextField();
  89. textfield.embedFonts = true;
  90. textfield.autoSize = TextFieldAutoSize.LEFT;
  91. textfield.selectable = false;
  92. textfield.defaultTextFormat = textformat;
  93. textfield.text = 'init...';
  94. addChild( textfield );
  95. infoTimer = new Timer( 2500, 0 );
  96. infoTimer.addEventListener( TimerEvent.TIMER, onNextInfo );
  97. }
  98. private function onNextInfo( event: TimerEvent ): void
  99. {
  100. if( ++infoIndex >= songCredits.length ) infoIndex = 0;
  101. textfield.text = songNo + ': ' + songCredits[ infoIndex ];
  102. }
  103. }
  104. }