gpt4 book ai didi

java - 播放音效 (mp3)

转载 作者:行者123 更新时间:2023-12-01 15:13:06 24 4
gpt4 key购买 nike

有人知道如何用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();

这是错误消息:

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)

根据Java文档,

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.

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

最佳答案

我想你想要toURL()

关于java - 播放音效 (mp3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12031795/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com