Results 1 to 16 of 16
  1. #1
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default Opening mp3 file ( not reading )

    well i have a mp3 file on my desktop and after i run my program, i want it to open it..
    basically like opening it with double clicking on it, but ill just give my program a path.

    Java Code:
    C:\Users\Desktop\powerhit.mp3
    actually the mp3 is a radiochannel streaming link or smthing like that

    this is what happens when i open it normally.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Your question may be missing some information. For one, I'm not sure how it relates to Java programming.

    Luck.

  3. #3
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    well my whole idea is that ... my java code (program) is running and if certain something occurs, then i want java to open the mp3 file

    hows this not java programming ? hmmz :(

  4. #4
    leke's Avatar
    leke is offline Member
    Join Date
    Jun 2010
    Location
    Tampere, Finland
    Posts
    3
    Rep Power
    0

    Default

    It might help if you post the java code you are currently using to try and open the MP3 streaming link. Then maybe someone could show you where you are going wrong?

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Sorry, I got it. So how in your Java program do you try to call the program that plays the mp3 code? Are you using Runtime.exec(...)? If so, are you running into problems? Again, more details may help.

    edit: and if you are using Runtime.exec(...) have you read this article? http://www.javaworld.com/javaworld/j...229-traps.html

    Luck.

  6. #6
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    this is what im doing..

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    
    
    public class Counter {
    	public static void main(String[] args) throws Exception {
    		Robot robot = new Robot();
    		robot.delay(3000);
    	    Runtime load = Runtime.getRuntime();
            load.exec("C:/Users/Jansu/Desktop/powerhit.mp3");	    
    	}
    }
    ˇ


    Java Code:
    Exception in thread "main" java.io.IOException: Cannot run program "C:/Users/Jansu/Desktop/powerhit.mp3": CreateProcess error=193, %1 is not a valid Win32 application
    	at java.lang.ProcessBuilder.start(Unknown Source)
    	at java.lang.Runtime.exec(Unknown Source)
    	at java.lang.Runtime.exec(Unknown Source)
    	at java.lang.Runtime.exec(Unknown Source)
    	at Counter.main(Counter.java:12)
    Caused by: java.io.IOException: CreateProcess error=193, %1 is not a valid Win32 application
    	at java.lang.ProcessImpl.create(Native Method)
    	at java.lang.ProcessImpl.<init>(Unknown Source)
    	at java.lang.ProcessImpl.start(Unknown Source)
    	... 5 more

  7. #7
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    load.exec("C:/Users/Jansu/Desktop/powerhit.mp3");

    the arguments inside of .exec is not a valid file path.

  8. #8
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    no it seems to me that the path is valid, but with load.exec i can open only exe files not mp3 files ?

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,535
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Char View Post
    no it seems to me that the path is valid, but with load.exec i can open only exe files not mp3 files ?
    Yep, you can't run it like that (for an example type in the file path within a shell/command line interpreter). You have to run an mp3 player with the file as an argument.

    kind regards,

    Jos

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

    Default

    Provided the computer has a default application associated with mp3 files, you can run it via Desktop#open(...)

    db

  11. #11
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default

    Hi,

    Darryl's solution is probably the simplest to your requirement. And you need Java 1.6 to use the java.awt.Desktop class.

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,535
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by wsaryada View Post
    Hi,

    Darryl's solution is probably the simplest to your requirement. And you need Java 1.6 to use the java.awt.Desktop class.
    But then the question arises: "how can I define a default file type association in Java?" because people want to do everything in Java on their MS Windows PC.

    kind regards,

    Jos

  13. #13
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default

    I think for the default file type association should be better handled by the operating system :) Or, if you still want to do it you can execute the "assoc" or "ftype" command if you are using MS Windows.
    Last edited by wsaryada; 08-28-2010 at 03:35 PM.

  14. #14
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    im sure its possible to change association with java too hehe
    but thanks darryl...you solved it
    Java Code:
    import java.awt.*;
    import java.io.*;
    
    public class Test 
    { 
    
       public static void main (String[] args) throws Exception {
    
             Desktop d = Desktop.getDesktop(); 
             File f = new File("C:/Users/Jansu/Desktop/powerhit.mp3"); 
             d.open(f); 
       }       
    }
    SOLVED
    Last edited by Char; 08-28-2010 at 08:08 PM.

  15. #15
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

    Default

    Quote Originally Posted by Char View Post
    im sure its possible to change association with java too hehe
    Ah, the misplaced overconfidence of youth! No, it can't be done *with* Java. It may be possible *from* Java via JNI/JNA and a C/C++ program.

    Quote Originally Posted by Char View Post
    but thanks darryl...you solved it
    You're welcome.

    db

  16. #16
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    got it working like this also


    Java Code:
    import java.awt.*;
    import java.io.*;
    
    public class Test 
    { 
    
       public static void main (String[] args) throws Exception {
    	   Runtime load = Runtime.getRuntime(); 
    	   load.exec(" \"C:/Program Files (x86)/VideoLAN/VLC/vlc.exe\" \"C:\\Users/Jansu/Desktop/powerhit.mp3\" ");
       }       
    }
    weirdest thing is that when i change the \\ infront of users to / it gives me an error


Similar Threads

  1. Opening .html file
    By Prajin in forum New To Java
    Replies: 7
    Last Post: 08-06-2010, 07:20 AM
  2. Error While Opening A PDF file
    By Cluster Storm in forum AWT / Swing
    Replies: 6
    Last Post: 06-07-2010, 06:03 PM
  3. Opening applet with .html file
    By Atriamax in forum New To Java
    Replies: 12
    Last Post: 09-13-2009, 06:26 AM
  4. Opening a custom proyect file
    By janpol1 in forum Eclipse
    Replies: 0
    Last Post: 02-04-2009, 02:29 PM
  5. Problem in opening a file
    By Raghav kv in forum New To Java
    Replies: 1
    Last Post: 08-11-2007, 01:55 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
  •