Results 1 to 6 of 6
- 07-20-2011, 05:55 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 17
- Rep Power
- 0
Opening an mp3 file in the default external player.
Hi, i am having a problem opening an mp3 in the systems default player. I dont want the mp3 to be launched with the program but with the systems media player (e.g. vlc, windows media player, winamp etc whatever it may be)
here is the code i am currently using:
String tempFile = f.getAbsolutePath();
tempFile = tempFile.replaceAll("%20"," ");
File temp = new File(tempFile);
document = temp;
Desktop dt = Desktop.getDesktop();
dt.open(document);
the error i get is this:
java.io.IOException: Failed to open file:/C:/Users/matt/Documents/NetBeansProjects/theProject/test.mp3. Error message: Unspecified error
any suggestions? am i doing it wrong? been stuck on this for a solid hour now and google searching hasnt helped :( thx for any help
- 07-20-2011, 06:02 PM #2
Please post the FULL text of the error message. It has information. Like what line did the error occur on.
Also where is the variable: document defined? Add a println to print out the value of document before it is used by the open() method.
- 07-20-2011, 06:17 PM #3
Member
- Join Date
- Jun 2011
- Posts
- 17
- Rep Power
- 0
private File document;
at the start just under the class it is ok the variables are fine and im sorry here is the rest of the error:
java.io.IOException: Failed to open file:/C:/Users/matt/Documents/NetBeansProjects/theProject/test.mp3. Error message: Unspecified error
at sun.awt.windows.WDesktopPeer.ShellExecute(WDesktop Peer.java:59)
at sun.awt.windows.WDesktopPeer.open(WDesktopPeer.jav a:36)
at java.awt.Desktop.open(Desktop.java:254)
at theproject.downloadGUI.jButton2ActionPerformed(dow nloadGUI.java:101)
at theproject.downloadGUI.access$000(downloadGUI.java :10)
at theproject.downloadGUI$1.actionPerformed(downloadG UI.java:42)
at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.jav a:6288)
at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
at java.awt.Component.processEvent(Component.java:605 3)
at java.awt.Container.processEvent(Container.java:204 1)
at java.awt.Component.dispatchEventImpl(Component.jav a:4651)
at java.awt.Container.dispatchEventImpl(Container.jav a:2099)
at java.awt.Component.dispatchEvent(Component.java:44 81)
at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4168)
at java.awt.Container.dispatchEventImpl(Container.jav a:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478 )
at java.awt.Component.dispatchEvent(Component.java:44 81)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:643)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:616)
at java.awt.EventQueue$2.run(EventQueue.java:614)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 613)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)
here is the output from some printlns i added
System.out.println("Document: "+ document);
System.out.println("Document getAbsolutePath: "+ document.getAbsolutePath());
System.out.println("Document getCanonicalPPath: "+ document.getCanonicalPath());
System.out.println("Document getPath: "+ document.getPath());
System.out.println("Document getName: "+ document.getName());
==
Document: C:\Users\matt\Documents\NetBeansProjects\theProjec t\downloads\Test.mp3
Document getAbsolutePath: C:\Users\matt\Documents\NetBeansProjects\theProjec t\downloads\Test.mp3
Document getCanonicalPPath: C:\Users\matt\Documents\NetBeansProjects\theProjec t\downloads\Test.mp3
Document getPath: C:\Users\matt\Documents\NetBeansProjects\theProjec t\downloads\Test.mp3
Document getName: Test.mp3
- 07-20-2011, 06:35 PM #4
Member
- Join Date
- Jun 2011
- Posts
- 17
- Rep Power
- 0
what i have noticed is that the file:/ part is only one /
try entering that into something like ie or chrome or firefox it should correct it to have file:///
do you think that could be the problem? and how would i fix that because it isnt in the filepath i am feeding it.
- 07-20-2011, 06:46 PM #5
Try using another file like a .txt file and see what happens. Maybe the OS doesn't know what to do when Java asks it for the program for .mp3 files.
- 07-20-2011, 06:59 PM #6
Member
- Join Date
- Jun 2011
- Posts
- 17
- Rep Power
- 0
Similar Threads
-
How do you make a file save with a default file extension?
By Dark in forum New To JavaReplies: 3Last Post: 06-21-2011, 04:51 PM -
Sound file player
By yourdaddy in forum NetBeansReplies: 9Last Post: 05-25-2010, 03:36 AM -
opening default browser window in invisible mode
By robby14 in forum Advanced JavaReplies: 1Last Post: 02-20-2010, 01:50 AM -
Opening Text Files with Default System Editor
By Pesch in forum Advanced JavaReplies: 5Last Post: 10-08-2008, 06:17 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks