播放音效(mp3)

时间:2012-08-20 02:54:52

标签: java mp3 media-player jmf javasound

有谁知道如何在Java中播放mp3文件?我有一点声音效果,我想玩。这就是我所拥有的

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();

这是错误消息:

  

找不到适合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)

根据Java文档,

  

创建播放器的最简单方法是使用URI语法中的定位器。给定定位器,createPlayer将创建适合处理定位器标识的媒体的播放器。

但我不知道我做错了什么。有人可以帮忙吗?谢谢!

1 个答案:

答案 0 :(得分:1)

我想你想要toURL()