Advertisement
warodri

BlackBery Radio Test

Jun 24th, 2011
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. import javax.microedition.media.Manager;
  2. import javax.microedition.media.Player;
  3. import javax.microedition.media.control.VideoControl;
  4. import javax.microedition.media.control.VolumeControl;
  5. import net.rim.device.api.ui.UiApplication;
  6. import net.rim.device.api.ui.component.ButtonField;
  7. import net.rim.device.api.ui.component.Dialog;
  8. import net.rim.device.api.ui.component.EditField;
  9. import net.rim.device.api.ui.container.MainScreen;
  10.  
  11. public class MyRadio extends UiApplication
  12. {
  13. public static void main(String[] args)
  14. {
  15. MyRadio app = new MyRadio();
  16. app.enterEventDispatcher();
  17. }
  18. public MyRadio()
  19. {
  20. AudioScreen screen = new AudioScreen();
  21. pushScreen( screen );
  22. }
  23.  
  24. }
  25. class AudioScreen extends MainScreen
  26. {
  27. /* player */
  28. Player player;
  29. VolumeControl vc;
  30. VideoControl videoControl;
  31.  
  32. EditField _editUrl = new EditField( "Shoutcast Url: ", "http://67.159.41.241:80" );
  33.  
  34. public AudioScreen()
  35. {
  36. /* URL a transmitir */
  37. String url = "";
  38.  
  39. add ( _editUrl );
  40.  
  41. add ( new ButtonField("Play")
  42. {
  43. protected boolean navigationUnclick(int status, int time)
  44. {
  45. play();
  46. return true;
  47. }
  48. });
  49.  
  50. add ( new ButtonField("Pause")
  51. {
  52. protected boolean navigationUnclick(int status, int time)
  53. {
  54. pause();
  55. return true;
  56. }
  57. });
  58. add ( new ButtonField("Stop")
  59. {
  60. protected boolean navigationUnclick(int status, int time)
  61. {
  62. stop();
  63. return true;
  64. }
  65. });
  66.  
  67. }
  68.  
  69.  
  70.  
  71.  
  72.  
  73. // ** PLAYER
  74.  
  75. private void play()
  76. {
  77. try
  78. {
  79. player = Manager.createPlayer( _editUrl.getText() + ";deviceside=true" );
  80.  
  81. if ( player != null )
  82. {
  83. player.realize();
  84. player.start();
  85. }
  86. else
  87. {
  88. Dialog.alert( "Error al iniciar el reproductor!" );
  89. }
  90. }
  91. catch (Exception e)
  92. {
  93. System.out.println( e.getMessage() );
  94. }
  95.  
  96. }
  97.  
  98. private void pause()
  99. {
  100. try
  101. {
  102. if ( player != null && player.getState() == Player.STARTED )
  103. {
  104. player.stop();
  105. }
  106. else
  107. {
  108. Dialog.alert( "Error al pausar el reproductor!" );
  109. }
  110. }
  111. catch (Exception e)
  112. {
  113. System.out.println( e.getMessage() );
  114. }
  115.  
  116. }
  117.  
  118. private void stop()
  119. {
  120. pause();
  121. player = null;
  122. }
  123.  
  124. public boolean onClose()
  125. {
  126. stop();
  127.  
  128. return super.onClose();
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement