How to play mp3 and wav in Java

0 votes
Please guide me.
Jul 9, 2018 in Java by Akrati
• 3,190 points
6,142 views

2 answers to this question.

0 votes

Java FX has Media and MediaPlayer classes which will play mp3 files.

Example:

String bip = "bip.mp3";
Media hit = new Media(new File(bip).toURI().toString());
MediaPlayer mediaPlayer = new MediaPlayer(hit);
mediaPlayer.play();

You will need the following import statements:

import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
answered Jul 9, 2018 by Daisy
• 8,140 points
I think these classes only works with JavaFX Toolkit it doesnt work with JFrame
0 votes

We can use Java API to play .wav :

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
AudioInputStream audioInput = AudioSystem.getAudioInputStream(MyClazz.class.getResource("musicDemo.wav"));
Clip clip = AudioSystem.getClip();
clip.open(audioInput);
clip.start();
answered Dec 7, 2018 by Sushmita
• 6,920 points

Related Questions In Java

0 votes
2 answers

When and how to use Super() keyword in Java?

super() is used to call immediate parent. super() can be ...READ MORE

answered Jul 9, 2018 in Java by Sushmita
• 6,920 points
1,870 views
0 votes
1 answer

how to play sound in java?

 The following code will work fine. But I ...READ MORE

answered Jun 20, 2018 in Java by scarlett
• 1,290 points
1,491 views
0 votes
1 answer

How to convert or cast hashmap to JSON object in Java, and again convert JSON object to JSON string?

You can use: new JSONObject(map); READ MORE

answered Jun 27, 2018 in Java by Akrati
• 3,190 points
7,000 views
0 votes
1 answer

how to read csv file form sftp connection and store into string object in java code and convert into json.....post it using rest api

Hey, @Pooja, Before starting with anything you should ...READ MORE

answered May 13, 2020 in Java by Roshni
• 10,480 points
3,833 views
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 81,243 views
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
8,364 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points
17,443 views
0 votes
1 answer

Selenium JARS(Java) missing from downloadable link

Nothing to worry about here. In the ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points

edited Aug 4, 2023 by Khan Sarfaraz 4,882 views
0 votes
1 answer

How to getters and setters work in java

In Java, getter and setter are two ...READ MORE

answered Jun 1, 2018 in Java by Daisy
• 8,140 points
1,728 views
+2 votes
1 answer

How to import an existing x509 certificate and private key in Java keystore to use in SSL?

keytool does not provide such basic functionality ...READ MORE

answered Dec 19, 2018 in Java by Daisy
• 8,140 points
2,594 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP