5 Replies - 1033 Views - Last Post: 10 July 2014 - 04:31 PM Rate Topic: -----

#1 mattcash83   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 50
  • Joined: 23-June 12

Java Media Player - Controlling it behind the scenes

Posted 06 July 2014 - 05:54 PM

I am trying to create an MP3 player with a totally customized look and feel to it. I know how to do this with .net, but I must be missing something in Java.

I want to be able to NOT have to present the user with the default mediaPlayer.getControlPanelComponent() in order to control the media player. I want to be able to code it to when the user clicks on my "Play" button, I can tell the player to play the song, and so on.

so far I get this far:

try {
            player = Manager.createPlayer(playit.toURI().toURL());
            player.start();
            //Component c = player.getControlPanelComponent();
        } catch (IOException | NoPlayerException ex) {
            Logger.getLogger(TagTester.class.getName()).log(Level.SEVERE, null, ex);
        }



...but cannot seem to find out where to go from there.

If anyone is familiar with AxWindowMediaPlayer in .NET, I am looking for something similar to:

AxWindowMediaPlayer.Ctlcontrols.play()

when my "Play" button is clicked.

Any help or critique is accepted, thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Java Media Player - Controlling it behind the scenes

#2 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3599
  • View blog
  • Posts: 16,450
  • Joined: 20-September 08

Re: Java Media Player - Controlling it behind the scenes

Posted 07 July 2014 - 06:49 AM

Quote

I am trying to create an MP3 player with a totally customized look and feel to it.
In that case, you're probably better off using JavaFX
Was This Post Helpful? 1
  • +
  • -

#3 mattcash83   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 50
  • Joined: 23-June 12

Re: Java Media Player - Controlling it behind the scenes

Posted 07 July 2014 - 03:49 PM

Thanks Goose.

I am looking into JavaFX right now. I am curious though whether it is possible using JFM at all. From what I am seeing in my look into JavaFX it seems very high level and bulky. I may be wrong, but still curious all the same.

Thanks again for pointing me in a workable direction!!
Was This Post Helpful? -1
  • +
  • -

#4 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3599
  • View blog
  • Posts: 16,450
  • Joined: 20-September 08

Re: Java Media Player - Controlling it behind the scenes

Posted 08 July 2014 - 01:39 AM

It's not as easy to customize the GUI in a radical way with standard Java. AFAIK JavaFX integrates with the normal JSE API so if you need to adjust lower level elements, that should be OK too. I'm no expert on JavaFX but i'm fairly certain it would be the way to go for you
Was This Post Helpful? 0
  • +
  • -

#5 farrell2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 874
  • View blog
  • Posts: 2,706
  • Joined: 29-July 11

Re: Java Media Player - Controlling it behind the scenes

Posted 09 July 2014 - 05:53 AM

You use .net and java and are worried about code being to high level? Wow...

Anyway, MediaPlayer, Media, and MediaView are simple to use.
Was This Post Helpful? -1
  • +
  • -

#6 mattcash83   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 50
  • Joined: 23-June 12

Re: Java Media Player - Controlling it behind the scenes

Posted 10 July 2014 - 04:31 PM

Again thank you gOOse.

I was finally able to look into javaFX and incorporate it into what I am trying to do. I will admit it had me scratching my head for a little bit, but I was able to finally figure out what my problem is.

Here is the simplified version of what I was asking for in OP:

    import javafx.scene.media.MediaPlayer;
    import javafx.scene.media.Media;
    import javafx.embed.swing.JFXPanel;
    import java.net.URL;

    public void Main() {

        JFXPanel fxPanel = new JFXPanel();
    
        private void myPlayButtonGotPushed(java.awt.event.ActionEvent evt) {                                         
            //Play Button Pressed
        
            URL myFile = getClass().getResource("song.mp3");
            Media song = new Media(myFile);
            MediaPlayer player = new MediaPlayer(song);
            player.play();

        }
    }




The catch is with what I have in line 08, which is something you MUST do to initialize the MediaPlayer as it does not initialize itself when you call line 15 (this had me going in circles on Google).

Of course there are many other goodies to use with javaFX in an MP3 player project, but I figured I would go ahead and post this in case anyone was wondering the same thing.
Was This Post Helpful? -1
  • +
  • -

Page 1 of 1