Results 1 to 6 of 6
  1. #1
    mattxo is offline Member
    Join Date
    Jun 2011
    Posts
    17
    Rep Power
    0

    Default 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

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    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.

  3. #3
    mattxo is offline Member
    Join Date
    Jun 2011
    Posts
    17
    Rep Power
    0

    Default

    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

  4. #4
    mattxo is offline Member
    Join Date
    Jun 2011
    Posts
    17
    Rep Power
    0

    Default

    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.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    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.

  6. #6
    mattxo is offline Member
    Join Date
    Jun 2011
    Posts
    17
    Rep Power
    0

    Default

    hmm i think you are correct, when the extension is .txt it opens in notepad with no problems at all , shame.

    I guess ill just have to open it with windows media player lol

Similar Threads

  1. Replies: 3
    Last Post: 06-21-2011, 04:51 PM
  2. Sound file player
    By yourdaddy in forum NetBeans
    Replies: 9
    Last Post: 05-25-2010, 03:36 AM
  3. opening default browser window in invisible mode
    By robby14 in forum Advanced Java
    Replies: 1
    Last Post: 02-20-2010, 01:50 AM
  4. Opening Text Files with Default System Editor
    By Pesch in forum Advanced Java
    Replies: 5
    Last Post: 10-08-2008, 06:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •