Reputation: 21237
Does anyone know how to play an mp3 file in Java? I have a little sound effect that I want to play. Here's what I have
import java.io.*;
import java.media.*;
File mp3Correct;
Player correct;
/* Load mp3 files */
mp3Correct = new File ("C:\\correct.mp3");
/* Create media players */
correct = Manager.createPlayer( mp3Correct.toURI() ); //<--error
/* Play the sound effect */
correct.start();
This is the error message:
no suitable method found for createPlayer(URI)
method Manager.createPlayer(DataSource) is not applicable (actual argument URI cannot be converted to DataSource by method invocation conversion) method Manager.createPlayer(MediaLocator) is not applicable (actual argument URI cannot be converted to MediaLocator by method invocation conversion) method Manager.createPlayer(URL) is not applicable (actual argument URI cannot be converted to URL by method invocation conversion)
According to the Java documentation,
The simplest way to create a Player is from a locator in the URI syntax. Given a locator, createPlayer will create a Player suitable to handle the media identified by the locator.
But I don't know what I am doing wrong. Can anyone help? Thank you!
Upvotes: 0
Views: 432