Advertisement
Guest User

Radio

a guest
Jun 26th, 2017
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. package fr.nelosia.radio;
  2.  
  3. import java.io.PrintStream;
  4. import java.net.URL;
  5. import javazoom.jl.player.JavaSoundAudioDevice;
  6. import javazoom.jl.player.Player;
  7. import net.minecraft.client.Minecraft;
  8.  
  9. public class Radio
  10. {
  11. private String streamURL = "http://streaming.radio.funradio.fr/fun-1-48-192";
  12. private static Player player;
  13. private static float volume;
  14.  
  15. public Radio(float vol)
  16. {
  17. System.out.println("Initializing radio...");
  18. volume = vol;
  19. }
  20.  
  21. public void startPlayer()
  22. {
  23. try
  24. {
  25. Thread t = new Thread()
  26. {
  27. public void run()
  28. {
  29. try
  30. {
  31. Radio.setbounds(new Player(new URL(Radio.this.streamURL).openStream()));
  32. Minecraft.getMinecraft().isRadioPlaying = true;
  33. JavaSoundAudioDevice.radioVolume = Radio.volume;
  34. Radio.player.play();
  35. }
  36. catch (Exception e)
  37. {
  38. e.printStackTrace();
  39. }
  40. }
  41. };
  42. t.start();
  43. }
  44. catch (Exception e)
  45. {
  46. e.printStackTrace();
  47. }
  48. }
  49.  
  50. public void stop()
  51. {
  52. if ((player != null) && (isPlaying()))
  53. {
  54. volume = 0.0F;
  55. JavaSoundAudioDevice.radioVolume = -1500.0F;
  56. RadioSlider.field_146134_p = 0.0F;
  57. player.close();
  58. Minecraft.getMinecraft().isRadioPlaying = false;
  59. }
  60. }
  61.  
  62. public boolean isPlaying()
  63. {
  64. return Minecraft.getMinecraft().isRadioPlaying;
  65. }
  66.  
  67. public static void setVolume(float f)
  68. {
  69. if (player != null)
  70. {
  71. volume = f;
  72. JavaSoundAudioDevice.radioVolume = f * 46.0F - 40.0F;
  73. if (f <= 0.0F) {
  74. JavaSoundAudioDevice.radioVolume = -1500.0F;
  75. }
  76. }
  77. }
  78.  
  79. public float getVolume()
  80. {
  81. return JavaSoundAudioDevice.radioVolume;
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement