java 包 javax.media 不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30692366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
package javax.media does not exist
提问by Masu
I am working on an audio player and need to add pause()
and play()
features in it to connect with JButtons
. The problem is I am not able to import Media package as it says package does not exist. I cannot find anywhere it online to download the package. Same goes for AudioPlayer
class which gives bad class file error.
我工作的音频播放器,并需要添加pause()
和play()
功能在它与连接JButtons
。问题是我无法导入媒体包,因为它说包不存在。我在网上找不到任何地方可以下载该软件包。这同样适用于AudioPlayer
类会带来坏的类文件错误。
回答by Anptk
Based on your question,
根据你的问题,
You can down load java.media
你可以下载java.media
then use
然后使用
import javax.media.*;
then you can declare like
然后你可以声明像
Player audioplayer = Manager.createRealizedPlayer(file.toURI().toURL());
And
和
audioplayer.start();
and audioplayer.stop();
audioplayer.start();
和 audioplayer.stop();
Here file
means where the source file saved.
这里file
表示源文件的保存位置。
NB: you can use JMF jar file
注意:您可以使用 JMF jar 文件
Try like this
像这样尝试
try {
audioplayer = Manager.createRealizedPlayer(file.toURI().toURL());
} catch (IOException ex) {
Logger.getLogger(MY_MP3_PLAYER.class.getName()).log(Level.SEVERE, null, ex);
} catch (NoPlayerException ex) {
Logger.getLogger(MY_MP3_PLAYER.class.getName()).log(Level.SEVERE, null, ex);
} catch (CannotRealizeException ex) {
Logger.getLogger(MY_MP3_PLAYER.class.getName()).log(Level.SEVERE, null, ex);
}
OR Try the sample code given below
或尝试下面给出的示例代码
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import javax.media.CannotRealizeException;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
public class Mp3Player {
public static void main(String[] args) throws IOException, NoPlayerException, CannotRealizeException {
// Source of song file
File f=new File("your path in which mp3 file is saved");
// Create a Player object that realizes the audio
final Player p=Manager.createRealizedPlayer(f.toURI().toURL());
// Start the music
p.start();
// Create a Scanner object for taking input from cmd
Scanner s=new Scanner(System.in);
// Read a line and store it in st
String st=s.nextLine();
// If user types 's', stop the audio
if(st.equals("s"))
{
p.stop();
}
}
}
回答by AntJavaDev
you need the JMF libraries , you can get them from there , for windows there is a typic installer :
您需要 JMF 库,您可以从那里获取它们,对于 Windows,有一个典型的安装程序:
回答by aristotll
It is a late answer, but you can use the Maven dependency:
这是一个迟到的答案,但您可以使用 Maven 依赖项:
<!-- https://mvnrepository.com/artifact/javax.media/jmf -->
<dependency>
<groupId>javax.media</groupId>
<artifactId>jmf</artifactId>
<version>2.1.1e</version>
</dependency>
回答by VD007
Following four packages will solve your problem. They contains most of helpful methods to deal with audio player.
以下四个包将解决您的问题。它们包含大多数处理音频播放器的有用方法。
import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.AudioDevice;
import javazoom.jl.player.FactoryRegistry;
import javazoom.jl.player.advanced.AdvancedPlayer;
You can use .stop(), start(), .play() etc. from above packages. Hope that will help.
您可以使用上述包中的 .stop()、start()、.play() 等。希望这会有所帮助。