Pages

Thursday 6 March 2014

Write a java program to play music on system default music player


 Save the file with name PalyMusic.java and run the program. The music will  play now.

Source Code:

public class PlayMusic{
 
 public static void main(String args[])
    {
        String windowsMediaPlayer="\"%programfiles%\\Windows Media Player\\wmplayer.exe\"";
        String songPath="E:\\kalimba.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