Plugin development primer: StartStopListener

Discuss issues related to PS3 Media Server development (only for programmers)

Plugin development primer: StartStopListener

Postby el.botijo » Wed Feb 24, 2010 11:55 pm

As I do not have access to editing the wiki, I want to share this piece of code in case somebody wants to develop new plugins. You know, documentation could help getting people on board. Now, for the description here:

StartStopListener is related to the events of the media server starting (nowPlaying method) and ending (donePlaying) serving a media file.

Following quick example shows how the nowPlaying method is used to show a fairly annoying MessageBox.

Code: Select all
package net.pms.external;

import javax.swing.JComponent;
import javax.swing.JOptionPane;

import net.pms.dlna.DLNAMediaInfo;
import net.pms.dlna.DLNAResource;

public class AudioListenerSkel implements StartStopListener{

   @Override
   public void donePlaying(DLNAMediaInfo media, DLNAResource resource) {
      // TODO Auto-generated method stub
      
   }

   @Override
   public void nowPlaying(DLNAMediaInfo media, DLNAResource resource) {
      // Annoy all the people with a MessageBox when a file is being served
      JOptionPane.showMessageDialog(null,
            media.getFirstAudioTrack().songname,
            "Now Playing",
            JOptionPane.INFORMATION_MESSAGE);
      
   }

   @Override
   public JComponent config() {
      //Returns a JComponent that is usually a JPanel
      //Is called via a button in the General Configuration tab
      return null;
   }

   @Override
   public String name() {
      // Returns the label on the button that is being used for configuration
      return "Now Playing example";
   }

   @Override
   public void shutdown() {
      // In case you need to close some network link or file handler
   }
   

}
el.botijo
 
Posts: 50
Joined: Thu Feb 04, 2010 9:14 pm

Re: Plugin development primer: StartStopListener

Postby dradovic » Tue Apr 20, 2010 8:14 pm

Thanks for sharing!

However, I'm a Java newbie and I'm trying to figure out how to compile your example into a jar file which can be then copied to the plugins folder. Can you please give me a hint or point me to some additional material?

Cheers
dradovic
 
Posts: 7
Joined: Tue Apr 20, 2010 8:11 pm

Re: Plugin development primer: StartStopListener

Postby el.botijo » Tue Apr 20, 2010 9:11 pm

dradovic wrote:Thanks for sharing!

However, I'm a Java newbie and I'm trying to figure out how to compile your example into a jar file which can be then copied to the plugins folder. Can you please give me a hint or point me to some additional material?

Cheers

Hello,
what I did was, more or less:
  1. Install Eclipse
  2. In one workarea, setup SVN and download PSM source code
  3. In another workarea, create projects that link to the PSM source code
  4. When you code something that does not have any error, then you should be able to right click on the project and export as JAR.
That is more or less what I do. I think you can instead of downloading PSM source code, just point to the PSM.jar file that you have since you installed PSM. It is not as neat as that, but does the job.
For the two plugins I have created (shutdown and MediaMonkey), both of them have the source code included with the JAR file. That will be a starting point on what file structure PMS expects. It is important to note that there is a plugin file with some specific content in there.

If anyone knows better, please rectify my statements.

Update: I am not writing this from my development computer!
el.botijo
 
Posts: 50
Joined: Thu Feb 04, 2010 9:14 pm

Re: Plugin development primer: StartStopListener

Postby dradovic » Fri Apr 30, 2010 9:09 pm

Thank you very much for your kind explanations!

Finally, I got to the point where I have a config button for my plugin showing up in PMS. I struggled quite a lot until I've figured the need of that 'plugin' text-file (now I understand what you've meant by 'there is a plugin file with some specific content in there'). So, what I did is to manually create a text file containing the fully qualified classname and now it works.
I wonder how you've figured out the need for this file... is this some Java convention or PMS specific? Well anyway, it works now... so, thanks!
dradovic
 
Posts: 7
Joined: Tue Apr 20, 2010 8:11 pm

Re: Plugin development primer: StartStopListener

Postby el.botijo » Fri Apr 30, 2010 10:41 pm

What I did is see what other people have been doing. The last.fm was the first plugin I opened.
el.botijo
 
Posts: 50
Joined: Thu Feb 04, 2010 9:14 pm

Re: Plugin development primer: StartStopListener

Postby el.botijo » Fri Apr 30, 2010 10:47 pm

el.botijo wrote:What I did is see what other people have been doing. The last.fm was the first plugin I opened.

I think we really need to have a proper wiki up and running.
el.botijo
 
Posts: 50
Joined: Thu Feb 04, 2010 9:14 pm


Return to Developers

Who is online

Users browsing this forum: No registered users and 2 guests