10 Replies Latest reply: Jun 14, 2011 1:24 PM by captfoss RSS

    Set a list of files

    868464
      Hello people, how are u?!

      I have a problem and I searched in the internet but I couldn't find anything about it.
      I need to set a list of video files to play in the jmf, but I couldn't do that yet.
      Someone knows how can I do??
      I'll have a list of file paths and when the firts video finishes, change for the next video.

      Thank you very much.

      Sincerely,

      Rafael Souza e Silva.
        • 1. Re: Set a list of files
          captfoss
          865461 wrote:
          I have a problem and I searched in the internet but I couldn't find anything about it.
          I need to set a list of video files to play in the jmf, but I couldn't do that yet.
          Someone knows how can I do??
          You could modify the concat example to play instead of record...
          http://web.archive.org/web/20080316203600/http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Concat.html
          • 2. Re: Set a list of files
            868464
            Hello captfoss,

            I tried to use the Concat.java, but I'm having some problems.
            When I run the class, it returned to me errors, like the errors below:

            Failed to set the output content descriptor on the processor.
            Failed to concatenate the inputs

            Thank you,

            Best regards

            Rafael.
            • 3. Re: Set a list of files
              868464
              Hello captfoss,

              I was seeing your posts in the forum and i saw one that caught my attention about the playlist and you talk about the jukebox datasource.

              Do you have one example about this datasource!?
              And can you post this example for us?!

              I'm trying to use the Concat.java, but I'm finding some difficulties to make it work.


              So if you can help me, i'll be very grateful to you.

              Best regards,

              Rafael.
              • 4. Re: Set a list of files
                captfoss
                The concat example is the example of a jukebox datasource.

                You need to modify the code to play the list of files rather that storing them, which means either (1) set the content descriptor of the Processor to be null, or (2) replace the processor entirely with a Player object instead.

                There will be some processors internal to the custom DataSource. Don't touch those, only the processor that's being used on the output of the custom DataSource.

                I believe the example calls it a "super glue" datasource, which is what I personally call a "jukebox" datasource.
                • 5. Re: Set a list of files
                  868464
                  Hello captfoss,

                  I was searching in the forum and I found this class,
                  I tried to use this one and it working.

                  But now I need help again.. hehehe

                  Now my problem is, I need to put the class NewListPlayer below
                  public class NewListPlayer extends JFrame{
                  
                          private Player player = null;
                          private ArrayList<Player> players = new ArrayList<Player>();
                          private ArrayList<String> filelist = new ArrayList<String>();
                          private String path = "C:/";
                          private int playingIndex = -1;
                          public int lungime;
                          public int latime;
                          EventHandler handler = new EventHandler();
                  
                          public NewListPlayer(int lung, int lat) {
                              this.addWindowListener(
                                      new WindowAdapter() {
                  
                                          @Override
                                          public void windowClosing(WindowEvent e) {
                                              stop();
                                              System.exit(0);
                                          }
                                      });
                              lungime = lung;
                              latime = lat;
                              try {
                                  readList();
                              } catch (FileNotFoundException ex) {
                                  System.out.println(ex);
                              } catch (IOException ex) {
                                  System.out.println(ex);
                              }
                              getContentPane().setBackground(new Color(12,55,79));
                              playNextInList();
                              setSize(lungime, latime);
                              setVisible(true);
                          }
                  
                          // instead of opening just checking for readability
                          private boolean checkFile(String path) {
                              File file = new File(path);
                              boolean ret = false;
                              try {
                                  ret = file.canRead();
                                  file = null;
                                  return ret;
                              } catch (Exception e) {
                                  file = null;
                                  System.out.println("File cannot be read");
                                  return false;
                              }
                          }
                  
                          //this is very important method, extracts player from list for current locator,
                          //if player is already present in the list. Otherwise creates new player for the locator
                          // and adds to the list
                          private boolean PlayFile() {
                              try {
                                  player = players.get(playingIndex);
                                  player.setMediaTime(new Time(0));
                                  player.start();
                                  updatePlayer();
                              } catch (Exception ex1) {
                                  try {
                                      player = Manager.createPlayer(new MediaLocator(filelist.get(playingIndex)));
                                      player.addControllerListener(handler);
                                      players.add(player);
                                      player.start();
                                  } catch (Exception ex2) {
                                      ex2.getStackTrace();
                                      return false;
                                  }
                              }
                              return true;
                          }
                  //this method is called from controller event handler as well as playFile method
                          //used for adding visual and control components
                  
                          public void updatePlayer() {
                              Container c = getContentPane();
                              // load Visual and Control components if they exist
                              Component visualComponent = player.getVisualComponent();
                              if (visualComponent != null) {
                                  c.add(visualComponent);
                              }
                  //            Component controlsComponent = player.getControlPanelComponent();
                  //            if (controlsComponent != null) {
                  //                c.add(controlsComponent, BorderLayout.SOUTH);
                  //            }
                  //            c.doLayout();
                          }
                  
                          // same method used Scanner instead
                          private void readList() throws FileNotFoundException, IOException {
                              String str = "";
                              FileInputStream fstream = new FileInputStream(path + "lista.txt");
                              Scanner scan = new Scanner(fstream);
                              filelist.clear();
                              while (scan.hasNext()) {
                                  if (checkFile(str = scan.nextLine())) {
                                      //add "file:" if you don't already have this in the playlist file locators
                                      filelist.add("file:" + str);
                                  }
                              }
                              fstream.close();
                              scan.close();
                          }
                  
                          private void playNextInList() {
                              playingIndex++;
                              if (playingIndex == filelist.size()) {
                                  playingIndex = 0;
                              }
                              if (!PlayFile()) {
                                  playNextInList();
                              }
                          }
                  
                          //added this method for closing all players at window closing
                          void stop() {
                              for (Player p : players) {
                                  p.stop();
                                  p.close();
                              }
                          }
                  
                          private class EventHandler implements ControllerListener {
                  
                              public void controllerUpdate(ControllerEvent e) {
                                  if (e instanceof RealizeCompleteEvent) {
                                      updatePlayer();
                                  }
                                  if (e instanceof EndOfMediaEvent) {
                                      if (player.getVisualComponent() != null) {
                                          getContentPane().remove(player.getVisualComponent());
                                      }
                  //                    if (player.getControlPanelComponent() != null) {
                  //                        getContentPane().remove(player.getControlPanelComponent());
                  //                    }
                                      player.stop();
                                      playNextInList();
                                  }
                              }
                          }
                      }
                  into this class (PainelFrame) below:
                  public class PainelFrame extends JFrame {
                  
                      private ServerSocket server;
                      private int port = 7777;
                      private Socket socket;
                      private JLabel lblSenha;
                      private JLabel lblSenha1;
                      private JLabel lblMesa;
                      private JLabel lblMesa1;
                      private JPanel pCabecalho;
                      private JTextPane tpSenha;
                      private JTextPane tpMesa;
                      private JTextPane tpDpto;
                      private JLabel lblMov;
                      private JPanel pNot;
                      private JPanel pMedia;
                  
                      public PainelFrame() {
                          super("Gerenciador de Fila - Painel de Senha");
                          this.setDefaultCloseOperation(EXIT_ON_CLOSE);
                          this.setLayout(new GridBagLayout());
                  
                          GridBagConstraints c = new GridBagConstraints();
                  
                          try {
                              UIManager.setLookAndFeel(new WindowsLookAndFeel());
                              server = new ServerSocket(port);
                          } catch (IOException e) {
                              System.out.println(e);
                          } catch (UnsupportedLookAndFeelException ex) {
                              System.out.println(ex);
                          }
                  
                          pCabecalho = new JPanel(new GridBagLayout());
                          GridBagConstraints gbc = new GridBagConstraints();
                          pCabecalho.setBackground(new Color(12, 55, 79));
                  
                          lblSenha = new JLabel("Senha");
                          lblSenha.setFont(new Font("Arial", Font.BOLD, 80));
                          lblSenha.setForeground(Color.WHITE);
                          gbc.fill = GridBagConstraints.HORIZONTAL;
                          gbc.gridx = 0;
                          gbc.gridy = 0;
                          pCabecalho.add(lblSenha, gbc);
                  
                          lblSenha1 = new JLabel();
                          lblSenha1.setFont(new Font("Arial", Font.ITALIC, 60));
                          lblSenha1.setForeground(Color.WHITE);
                          gbc.fill = GridBagConstraints.VERTICAL;
                          gbc.gridx = 1;
                          gbc.gridy = 0;
                          gbc.gridwidth = 2;
                          pCabecalho.add(lblSenha1, gbc);
                  
                          tpSenha = new JTextPane();
                          StyledDocument doc2 = tpSenha.getStyledDocument();
                          MutableAttributeSet set2 = new SimpleAttributeSet();
                          StyleConstants.setAlignment(set2, StyleConstants.ALIGN_CENTER);
                          StyleConstants.setFontSize(set2, 250);
                          StyleConstants.setFontFamily(set2, "Arial");
                          StyleConstants.setBold(set2, true);
                          StyleConstants.setForeground(set2, Color.BLACK);
                          doc2.setParagraphAttributes(0, 0, set2, true);
                          tpSenha.setEditable(false);
                          tpSenha.setBorder(new LineBorder(Color.WHITE, 5, true));
                          tpSenha.setBackground(Color.GRAY);
                          tpSenha.setPreferredSize(new Dimension(721, 299));
                          gbc.gridx = 0;
                          gbc.gridy = 1;
                          gbc.gridwidth = 3;
                          pCabecalho.add(tpSenha, gbc);
                  
                          lblMesa = new JLabel("Mesa");
                          lblMesa.setFont(new Font("Arial", Font.BOLD, 80));
                          lblMesa.setForeground(Color.WHITE);
                          gbc.fill = GridBagConstraints.BOTH;
                          gbc.gridx = 3;
                          gbc.gridy = 0;
                          gbc.gridwidth = 1;
                          pCabecalho.add(lblMesa, gbc);
                  
                          lblMesa1 = new JLabel();
                          lblMesa1.setFont(new Font("Arial", Font.ITALIC, 60));
                          lblMesa1.setForeground(Color.WHITE);
                          gbc.fill = GridBagConstraints.VERTICAL;
                          gbc.gridx = 4;
                          gbc.gridy = 0;
                          pCabecalho.add(lblMesa1, gbc);
                  
                          tpMesa = new JTextPane();
                          StyledDocument doc = tpMesa.getStyledDocument();
                          MutableAttributeSet set = new SimpleAttributeSet();
                          StyleConstants.setAlignment(set, StyleConstants.ALIGN_CENTER);
                          StyleConstants.setFontSize(set, 250);
                          StyleConstants.setFontFamily(set, "Arial");
                          StyleConstants.setBold(set, true);
                          StyleConstants.setForeground(set, Color.WHITE);
                          doc.setParagraphAttributes(0, 0, set, true);
                          tpMesa.setEditable(false);
                          tpMesa.setBorder(new LineBorder(Color.WHITE, 5, true));
                          tpMesa.setBackground(new Color(12, 55, 79));
                          tpMesa.setPreferredSize(new Dimension(500, 299));
                          gbc.insets = new Insets(0, 5, 0, 0);
                          gbc.gridx = 3;
                          gbc.gridy = 1;
                          gbc.gridwidth = 2;
                          gbc.gridheight = 2;
                          pCabecalho.add(tpMesa, gbc);
                  
                          tpDpto = new JTextPane();
                          StyledDocument doc3 = tpDpto.getStyledDocument();
                          MutableAttributeSet set3 = new SimpleAttributeSet();
                          StyleConstants.setAlignment(set3, StyleConstants.ALIGN_CENTER);
                          StyleConstants.setFontSize(set3, 80);
                          StyleConstants.setFontFamily(set3, "Arial");
                          StyleConstants.setItalic(set3, true);
                          StyleConstants.setForeground(set3, Color.WHITE);
                          doc3.setParagraphAttributes(0, 0, set3, true);
                          tpDpto.setEditable(false);
                          tpDpto.setBorder(new LineBorder(Color.WHITE, 5, true));
                          tpDpto.setBackground(new Color(12, 55, 79));
                          gbc.fill = GridBagConstraints.BOTH;
                          gbc.insets = new Insets(5, 0, 0, 0);
                          gbc.gridx = 0;
                          gbc.gridy = 2;
                          gbc.gridwidth = 5;
                          pCabecalho.add(tpDpto, gbc);
                  
                          pMedia = new JPanel(new FlowLayout(FlowLayout.CENTER));
                          pMedia.setBackground(new Color(12, 55, 79));
                          NewListPlayer listPlayer = new NewListPlayer(400, 400); // I tried to put here, and I was make the class NewListPlayer like JPanel... but didn't work
                          //MediaPanel mp = new MediaPanel(new URL("file:/C:/Documents and Settings/Elton/Meus documentos/Meus vídeos/SynMomentum.mpg"));
                  
                          pMedia.add(listPlayer);
                  
                          pNot = new JPanel(new FlowLayout(FlowLayout.LEFT));
                          pNot.setBackground(new Color(12, 55, 79));
                          lblMov = new JLabel();
                          lblMov.setFont(new Font("Arial", Font.BOLD, 40));
                          lblMov.setForeground(Color.WHITE);
                          pNot.add(lblMov);
                  
                          c.gridx = 0;
                          c.gridy = 0;
                          this.getContentPane().add(pNot, c);
                          c.gridy = 1;
                          this.getContentPane().add(pMedia, c);
                          c.gridy = 2;
                          this.getContentPane().add(pCabecalho, c);
                      }
                  Can you help me?!

                  Thanks and Best Regards..

                  Rafael.
                  • 6. Re: Set a list of files
                    captfoss
                    rafaelMamangava wrote:
                    But now I need help again.. hehehe

                    Now my problem is, I need to put the class NewListPlayer below

                    Can you help me?!
                    Help you with what, exactly? You didn't ask a question or state a problem...
                    • 7. Re: Set a list of files
                      868464
                      So, I need to put the NewListPlayer inside the PainelFrame,
                      but the NewListPlayer is a JFrame and where I need to put it in the PainelFrame is a JPanel.

                      >
                      NewListPlayer listPlayer = new NewListPlayer(400, 400); *// I tried to put here, and I maked the class NewListPlayer like JPanel... but didn't work*
                      //MediaPanel mp = new MediaPanel(new URL("file:/C:/Documents and Settings/Elton/Meus documentos/Meus vídeos/SynMomentum.mpg"));

                      pMedia.add(listPlayer);
                      • 8. Re: Set a list of files
                        captfoss
                        rafaelMamangava wrote:
                        but the NewListPlayer is a JFrame and where I need to put it in the PainelFrame is a JPanel.
                        This is a swing question, not a JMF question.

                        No offense, but if you can't figure out how to solve this problem on your own... you need to take a couple of intro to java courses.
                        • 9. Re: Set a list of files
                          868464
                          no offense too, but I think you should be more humble.
                          This here is a forum and if you don't want to answer, you don't need to posting this kind of response.
                          And if I have some difficulties and if I need to study a little more, it's my problem, not your problem.
                          • 10. Re: Set a list of files
                            captfoss
                            rafaelMamangava wrote:
                            no offense too, but I think you should be more humble.
                            I have not said a single thing anywhere on this thread that remotely implies anything about myself...
                            This here is a forum and if you don't want to answer, you don't need to posting this kind of response.
                            You can assume by virtue of the fact that I did answer that I wanted to...

                            And I don't give two craps if you think my response was unnecessary, I think my response was both necessary and warrented.
                            And if I have some difficulties and if I need to study a little more, it's my problem, not your problem.
                            Which was exactly my point...

                            I enjoy helping people learn and understand the JMF principles, which is the reason I post here. If you're not ready to understand them because you're getting hung up on stuff that you should be able to take for granted, it's absolutely essential that you be told that.

                            It should be trivial to change a JFrame to a JPanel. If it's not, you either need to go back and study Swing a bit more, which is what I told you to do, or it's an engineering problem, which I'm happy to help with.

                            If you don't like my tone, then you're welcome to ask for your money back...