Choose Your Language

Monday, 24 June 2013

Java program to play music on system default music player

public class PlayMusicWithJava {
   
 public static void main(String args[])
    {
        String windowsMediaPlayer="\"%programfiles%\\Windows Media Player\\wmplayer.exe\"";
        String songPath="C:\\mymusic\\salsa.mp3"; // mymusic is the folder name
        try
        {     
        Runtime.getRuntime().exec("cmd /c start "+windowsMediaPlayer+" "+songPath);
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
    }
}

No comments:

Post a Comment