Player.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. * Copyright (C) 2014 iZc <nplusc.de>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. package de.nplusc.izc.izstreamer;
  19. import com.sun.jna.Memory;
  20. import java.awt.Canvas;
  21. import java.awt.Desktop;
  22. import java.io.IOException;
  23. import java.net.URI;
  24. import java.net.URISyntaxException;
  25. import javafx.application.Application;
  26. import javax.swing.JPanel;
  27. import uk.co.caprica.vlcj.player.direct.BufferFormat;
  28. import uk.co.caprica.vlcj.player.direct.DirectMediaPlayer;
  29. /**
  30. *
  31. * @author LH
  32. */
  33. public class Player extends javax.swing.JFrame implements PlayerStructure
  34. {
  35. /**
  36. * Creates new form Player
  37. * @param g refers to controller
  38. */
  39. public Player(StreamGUI g)
  40. {
  41. playmanager=g;
  42. initComponents();
  43. setResizable(false);
  44. }
  45. //public static final String StreamTitle = "";
  46. private StreamGUI playmanager;
  47. /**
  48. * This method is called from within the constructor to
  49. * initialize the form.
  50. * WARNING: Do NOT modify this code. The content of this method is
  51. * always regenerated by the Form Editor.
  52. */
  53. @SuppressWarnings("unchecked")
  54. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  55. private void initComponents()
  56. {
  57. sliderVolume = new javax.swing.JSlider();
  58. lblSender = new javax.swing.JLabel();
  59. lblTIT = new javax.swing.JLabel();
  60. btnPlay = new javax.swing.JButton();
  61. Info = new javax.swing.JButton();
  62. btnLastPlayed = new javax.swing.JButton();
  63. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  64. sliderVolume.setMajorTickSpacing(10);
  65. sliderVolume.setValue(100);
  66. sliderVolume.addMouseMotionListener(new java.awt.event.MouseMotionAdapter()
  67. {
  68. public void mouseDragged(java.awt.event.MouseEvent evt)
  69. {
  70. sliderVolumeMouseDragged(evt);
  71. }
  72. });
  73. lblSender.setText("Sender");
  74. lblTIT.setText("Now Playing:");
  75. btnPlay.setText("PLAY");
  76. btnPlay.addActionListener(new java.awt.event.ActionListener()
  77. {
  78. public void actionPerformed(java.awt.event.ActionEvent evt)
  79. {
  80. btnPlayActionPerformed(evt);
  81. }
  82. });
  83. Info.setText("Info");
  84. Info.addActionListener(new java.awt.event.ActionListener()
  85. {
  86. public void actionPerformed(java.awt.event.ActionEvent evt)
  87. {
  88. InfoActionPerformed(evt);
  89. }
  90. });
  91. btnLastPlayed.setText("Last 20 Tracks");
  92. btnLastPlayed.addActionListener(new java.awt.event.ActionListener()
  93. {
  94. public void actionPerformed(java.awt.event.ActionEvent evt)
  95. {
  96. btnLastPlayedActionPerformed(evt);
  97. }
  98. });
  99. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  100. getContentPane().setLayout(layout);
  101. layout.setHorizontalGroup(
  102. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  103. .addGroup(layout.createSequentialGroup()
  104. .addContainerGap()
  105. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  106. .addGroup(layout.createSequentialGroup()
  107. .addComponent(lblSender, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  108. .addGap(18, 18, 18)
  109. .addComponent(sliderVolume, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  110. .addGroup(layout.createSequentialGroup()
  111. .addComponent(lblTIT, javax.swing.GroupLayout.PREFERRED_SIZE, 397, javax.swing.GroupLayout.PREFERRED_SIZE)
  112. .addGap(0, 8, Short.MAX_VALUE))
  113. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  114. .addComponent(btnPlay, javax.swing.GroupLayout.PREFERRED_SIZE, 262, javax.swing.GroupLayout.PREFERRED_SIZE)
  115. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  116. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  117. .addComponent(Info, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  118. .addComponent(btnLastPlayed, javax.swing.GroupLayout.DEFAULT_SIZE, 114, Short.MAX_VALUE))))
  119. .addContainerGap())
  120. );
  121. layout.setVerticalGroup(
  122. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  123. .addGroup(layout.createSequentialGroup()
  124. .addContainerGap()
  125. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  126. .addComponent(lblSender)
  127. .addComponent(sliderVolume, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  128. .addGap(18, 18, 18)
  129. .addComponent(lblTIT)
  130. .addGap(18, 18, 18)
  131. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  132. .addGroup(layout.createSequentialGroup()
  133. .addComponent(Info)
  134. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  135. .addComponent(btnLastPlayed)
  136. .addGap(0, 0, Short.MAX_VALUE))
  137. .addComponent(btnPlay, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  138. .addContainerGap())
  139. );
  140. pack();
  141. }// </editor-fold>//GEN-END:initComponents
  142. public void updateSender(String s)
  143. {
  144. lblSender.setText(s);
  145. }
  146. private boolean isPlaying = false;
  147. private void btnPlayActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnPlayActionPerformed
  148. {//GEN-HEADEREND:event_btnPlayActionPerformed
  149. if(isPlaying)
  150. {
  151. playmanager.stopPlay=true;
  152. isPlaying=false;
  153. btnPlay.setText("PLAY");
  154. }
  155. else
  156. {
  157. btnPlay.setText("STOP");
  158. lblSender.setText("Connecting....");
  159. new Thread(()->
  160. playmanager.play()).start();
  161. //http://31.7.177.108:2299/played.html
  162. isPlaying=true;
  163. }
  164. }//GEN-LAST:event_btnPlayActionPerformed
  165. private void sliderVolumeMouseDragged(java.awt.event.MouseEvent evt)//GEN-FIRST:event_sliderVolumeMouseDragged
  166. {//GEN-HEADEREND:event_sliderVolumeMouseDragged
  167. playmanager.m.setVolume(sliderVolume.getValue());
  168. }//GEN-LAST:event_sliderVolumeMouseDragged
  169. private void InfoActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_InfoActionPerformed
  170. {//GEN-HEADEREND:event_InfoActionPerformed
  171. }//GEN-LAST:event_InfoActionPerformed
  172. private void btnLastPlayedActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnLastPlayedActionPerformed
  173. {//GEN-HEADEREND:event_btnLastPlayedActionPerformed
  174. try
  175. {
  176. Desktop.getDesktop().browse(new URI("http://31.7.177.108:2294/played.html"));
  177. }
  178. catch (URISyntaxException ex)
  179. {
  180. ex.printStackTrace();
  181. }
  182. catch (IOException ex)
  183. {
  184. ex.printStackTrace();
  185. }
  186. }//GEN-LAST:event_btnLastPlayedActionPerformed
  187. public void setPlaying(String tit)
  188. {
  189. lblTIT.setText("Now playing: "+tit);
  190. }
  191. @Override
  192. public Canvas getBackGround()
  193. {
  194. return null;
  195. }
  196. /**
  197. * @param args the command line arguments
  198. */
  199. public static void main(String args[])
  200. {
  201. /* Set the Nimbus look and feel */
  202. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  203. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  204. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  205. */
  206. try
  207. {
  208. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
  209. {
  210. if ("Nimbus".equals(info.getName()))
  211. {
  212. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  213. break;
  214. }
  215. }
  216. }
  217. catch (ClassNotFoundException ex)
  218. {
  219. java.util.logging.Logger.getLogger(Player.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  220. }
  221. catch (InstantiationException ex)
  222. {
  223. java.util.logging.Logger.getLogger(Player.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  224. }
  225. catch (IllegalAccessException ex)
  226. {
  227. java.util.logging.Logger.getLogger(Player.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  228. }
  229. catch (javax.swing.UnsupportedLookAndFeelException ex)
  230. {
  231. java.util.logging.Logger.getLogger(Player.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  232. }
  233. //</editor-fold>
  234. /* Create and display the form */
  235. java.awt.EventQueue.invokeLater(new Runnable()
  236. {
  237. public void run()
  238. {
  239. VisualizedGUI vgui = new VisualizedGUI();
  240. //vgui.setSize(iZstreamer.width, iZstreamer.height);
  241. vgui.validate();
  242. vgui.setVisible(true);
  243. //StreamGUI.player.play();
  244. //StreamGUI.player.setPlayerStructure(vgui);
  245. }
  246. });
  247. }
  248. // Variables declaration - do not modify//GEN-BEGIN:variables
  249. private javax.swing.JButton Info;
  250. private javax.swing.JButton btnLastPlayed;
  251. private javax.swing.JButton btnPlay;
  252. private javax.swing.JLabel lblSender;
  253. private javax.swing.JLabel lblTIT;
  254. private javax.swing.JSlider sliderVolume;
  255. // End of variables declaration//GEN-END:variables
  256. }