[英]Creating a music player with javafx and scene builder
I'm trying to create my own version of iTunes. 我正在尝试创建自己的iTunes版本。 I am trying to create a music player and this is my method: 我正在尝试创建音乐播放器,这是我的方法:
public void audioPlayerButtons(ActionEvent actionEvent) {
if (actionEvent.getSource() == playbtn) {
String bip = "/Users/april121/Work/MyMusic!/src/sample/Songs/01 Clarity.m4a";
Media hit = new Media(bip);
MediaPlayer mediaPlayer = new MediaPlayer(hit);
MediaPlayer.play();
}
else (actionEvent.getSource()== pausebtn){
MediaPlayer.pause();
}
else (actionEvent.getSource()==forwardbtn){
MediaPlayer.seek(MediaPlayer.getStartTime());
MediaPlayer.stop();
}
else (actionEvent.getSource()==backwardbtn){
//to be finished
}
But I have tried for hours now - be it through importing libraries from Maven or hard coding and it's not working. 但是我已经尝试了几个小时-无论是通过从Maven导入库还是进行硬编码,都无法正常工作。
I'd like it show what's playing and have basic functions ie. 我希望它显示正在播放的内容并具有基本功能,即。 play, pause, rewind and forward and have a progress bar. 播放,暂停,快退和快进,并具有进度条。
this is the error it is showing: 这是它显示的错误:
non-static method can't be accessed in static context. And the part that is causing the error is the ".stop()" or ".play()" bits
but I don't understand why - because my method is non-static anyways 但我不明白为什么-因为我的方法仍然是非静态的
Look at these lines: 看一下这些行:
MediaPlayer mediaPlayer = new MediaPlayer(hit);
MediaPlayer.play();
That second line is calling a static play()
function, which doesn't work. 第二行调用一个静态play()
函数,该函数不起作用。 The play()
function is non-static. play()
函数是非静态的。 That's why you're getting the error you're getting. 这就是为什么您遇到错误的原因。
You probably mean this instead: 您可能会这样说:
MediaPlayer mediaPlayer = new MediaPlayer(hit);
mediaPlayer.play();
If you have other questions, post them as separate questions and try to be as specific as possible. 如果您还有其他问题,请将其作为单独的问题发布,并尝试尽可能具体。
Try naming it something else ie. 尝试命名其他东西,即。
MediaPlayer mp = new MediaPlayer (hit);
mp.play();
That way you won't have a confusion! 这样您就不会感到困惑!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.