Results 1 to 10 of 10
Thread: Sound file player
- 05-19-2010, 08:48 PM #1
Member
- Join Date
- May 2010
- Posts
- 4
- Rep Power
- 0
- 05-20-2010, 04:46 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 05-20-2010, 12:04 PM #3
JFileChooser is used for selecting, not reading, files, so your statement is probably based on an incorrect assumption. To get better help sooner, post a SSCCE* that clearly demonstrates your problem.
* SSCCE : Java Glossary
And post your code using code tags.
db
- 05-20-2010, 05:11 PM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Still no feedback from the OP.
- 05-21-2010, 07:54 PM #5
Member
- Join Date
- May 2010
- Posts
- 4
- Rep Power
- 0
Alright thank you. sorry for not answering any sooner.
I have the file chooser working and I can import the file and it show it in a text field. And know i wanna be able to play that file. You could tell me what i should look into on java api. Any tips help.
This is the code i have so far
Java Code:package javaapplicationover9000; import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.SwingUtilities; public class Main extends JPanel implements ActionListener { static private final String newline = "\n"; JButton openButton, saveButton; JTextArea log; JFileChooser fc; public Main() { super(new BorderLayout()); log = new JTextArea(5,20); log.setMargin(new Insets(5,5,5,5)); log.setEditable(false); JScrollPane logScrollPane = new JScrollPane(log); fc = new JFileChooser(); openButton = new JButton("Open a File...", createImageIcon("http://www.java-forums.org/images/Open16.gif")); openButton.addActionListener(this); saveButton = new JButton("Save a File...", createImageIcon("http://www.java-forums.org/images/Save16.gif")); saveButton.addActionListener(this); JPanel buttonPanel = new JPanel(); buttonPanel.add(openButton); buttonPanel.add(saveButton); add(buttonPanel, BorderLayout.PAGE_START); add(logScrollPane, BorderLayout.CENTER); } public void actionPerformed(ActionEvent e) { if (e.getSource() == openButton) { int returnVal = fc.showOpenDialog(Main.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); log.append("Opening: " + file.getName() + "." + newline); } else { log.append("Open command cancelled by user." + newline); } log.setCaretPosition(log.getDocument().getLength()); } else if (e.getSource() == saveButton) { int returnVal = fc.showSaveDialog(Main.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); log.append("Saving: " + file.getName() + "." + newline); } else { log.append("Save command cancelled by user." + newline); } log.setCaretPosition(log.getDocument().getLength()); } } protected static ImageIcon createImageIcon(String path) { java.net.URL imgURL = Main.class.getResource(path); if (imgURL != null) { return new ImageIcon(imgURL); } else { System.err.println("Couldn't find file: " + path); return null; } } private static void createAndShowGUI() { JFrame frame = new JFrame("FileChooserDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new Main()); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { UIManager.put("swing.boldMetal", Boolean.FALSE); createAndShowGUI(); } }); } }Last edited by Eranga; 05-22-2010 at 12:36 PM. Reason: code tags added
- 05-22-2010, 12:37 PM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Please use code tags when you are posting here in the forum. Unformated codes are really hard to read. If you don't know how to do it, please check on my forum signature. You can see a link to relevant page.
- 05-22-2010, 12:38 PM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Regarding your question, read about the followings.
java.io.BufferedReader
import java.io.File;
import java.io.FileReader;
Other than that you've to use exceptions as well, but not that much interest at the initial step. Give a try and let us know.
- 05-22-2010, 12:39 PM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I think it's better to write a sample code first of all, before implement in your application.
- 05-24-2010, 11:26 PM #9
Member
- Join Date
- May 2010
- Posts
- 4
- Rep Power
- 0
Thank you very much that helped a lot. I appriciate people spending time to answer my questions.
- 05-25-2010, 03:36 AM #10
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Similar Threads
-
sound player
By jperson in forum New To JavaReplies: 1Last Post: 05-02-2010, 05:09 AM -
help with designing Java program:file browser w/ regex search, possibly media player?
By jmd9qs in forum New To JavaReplies: 0Last Post: 11-04-2009, 09:09 PM -
MP3 Player idea
By vinoth in forum New To JavaReplies: 3Last Post: 08-18-2009, 01:10 AM -
SWT Flash Player
By forthe in forum SWT / JFaceReplies: 0Last Post: 07-29-2008, 08:48 AM -
uploading sound file in java
By po0oker in forum Advanced JavaReplies: 8Last Post: 11-03-2007, 11:00 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks