I'm currently making an MP3 player on Java and I'd like to use Swing GUI elements exclusively if possible. But I also need the functionality of Media and MediaPlayer classes from JavaFX inside my program. Is there a way to instantiate only these logical elements in my application without the hassle of Scene making and the like? I honestly don't know much about them and I can't seem to understand very clearly the Oracle tutorials on it. Here's the places where I'd be using such items: (I call this class to a main class later on)
class MP3Panel extends JFrame
{
private Media playingnow;
private MediaPlayer player;
public MP3Panel()
{
player = new MediaPlayer(intoMedia(playlist.getFirstSong()));
player.setOnEndOfMedia(new Runnable() {
@Override
public void run() {
if(playlist.nextSong(thissong)==null)
{ player.stop();
nowplaying.setText("");
}
else
{
player = new MediaPlayer(intoMedia(playlist.nextSong(thissong)));
nowplaying.setText(thissong.printSongInfo());
player.play();
}
}
}
);
...
private Media intoMedia(Song a)
{
thissong = a;
thisfile = new File(thissong.getFilename());
thisURI = thisfile.toURI().toString();
playingnow = new Media(thisURI);
return playingnow;
}
I also use these for an ActionManager class:
private class ActionManager implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == playbtn)
{
if(playbtn.getIcon() == play)
{
if(player.getStatus()==MediaPlayer.Status.STOPPED)
{
player = new MediaPlayer(intoMedia(playlist.getFirstSong()));
nowplaying.setText(thissong.printSongInfo());
}
player.play();
playbtn.setIcon(pause);
}
else
{
player.pause();
playbtn.setIcon(play);
}
}
if(e.getSource() == fwdbtn)
{
if(playlist.nextSong(thissong) == null)
{
player.stop();
playbtn.setIcon(play);
}
else
{
player = new MediaPlayer(intoMedia(playlist.nextSong(thissong)));
nowplaying.setText(thissong.printSongInfo());
player.play();
playbtn.setIcon(pause);
}
}
There are also a backwards and forwards buttons there but I think this is enough to clarify what my dilemma is. Thanks in advance.