0

Is there anyone who can help me how to do this because it's difficult to know how to implement song in my simple program. I'm only beginner programmer and i want to know how to do that because i have a project regarding that. please help me in the simplest way because i'm not yet very good in java programming thanks ^_^

//this is my code. don't you think it's possible to do?

    public class Audio {

    public static void main(String[]args) throw IOException { 

    BufferedReader br = new BufferedReader (new InputStreamReader(System.in)); 

    String AudioAccept; 

    System.out.println("Would you like to play song?");
    AudioAccept = br.readLine(); 


    if(AudioAccept == Yes){
    // Play song which is what i want to know how to do.
    }else{
    System.out.println("Failed");
    }

    }
    }
default locale
  • 13,035
  • 13
  • 56
  • 62

1 Answers1

2

Import these

import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;

And then add these lines

String file = "sample.mp3"; 
Media myMedia = new Media(file); MediaPlayer mediaPlayer = new MediaPlayer(myMedia);
mediaPlayer.play();
Yogesh Patel
  • 672
  • 4
  • 9