Plugin development primer: AdditionalFolderAtRoot

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

Plugin development primer: AdditionalFolderAtRoot

Postby el.botijo » Sun Mar 07, 2010 10:24 pm

Part two of the plugin development primer. This one is called AdditionalFolderAtRoot and, as the message says, will create an additional folder at the root.

The plugin requires four methods/functions to be implemented:
  • name, used in the plugin list
  • config, returning a JComponent object that shows any configuration options onscreen. This is being called when the plugin list button is pressed.
  • shutdown, in case you need to clean up something, e.g. file or network handlers
  • getChild, returning a VirtualFolder item

The only specific item is the getChild function. For this function, you need to create a DLNAResource item. Typical DLNAResource are virtual folders (VirtualFolders) or playback items.

Following text is a short version of the code I created for the Shutdown plugin. It instantiates the VirtualVideoAction. When the user selects this item, PMS will issue the shutdown command to Windows (I had to make this short!). Instead of creating the folder structure whenever getChild() is called, I decided to create the folder when PMS starts and an instance of this class is created.

Code: Select all
package net.pms.external;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.io.IOException;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import com.sun.jna.Platform;

import net.pms.PMS;
import net.pms.dlna.DLNAResource;
import net.pms.dlna.virtual.VirtualFolder;
import net.pms.dlna.virtual.VirtualVideoAction;

/**Implements the Shutdown command for PS3MediaServer
 * @author chacaman
 * @version 0.1
 *
 */
public class ShutdownPlugin implements AdditionalFolderAtRoot{

   private VirtualFolder shutdownfolder;

   public ShutdownPlugin(){
      PMS.minimal("Shutdown Plugin - Creating ROOT");
      shutdownfolder = new VirtualFolder("Shutdown..., null); //$NON-NLS-1$

      if (Platform.isWindows()){
         PMS.minimal("Shutdown Plugin - Found Windows machine");
         shutdownfolder.addChild(new VirtualVideoAction("Power off", true) { //$NON-NLS-1$
            public boolean enable() {
               Runtime runtime = Runtime.getRuntime();
               try {
                  Process process = runtime.exec("ShutDown /s /f");
               } catch (IOException e) {}
               return true;
            }
         });
         PMS.minimal("Shutdown Plugin - Created POWEROFF node");
   }

   @Override
   public DLNAResource getChild() {
      return shutdownfolder;
   }

   @Override
   public JComponent config() {
      JPanel SDPanel = new JPanel(new GridBagLayout()); // Use GridBagLayout because it is flexible
      GridBagConstraints c = new GridBagConstraints();
      c.fill = GridBagConstraints.HORIZONTAL;
      c.anchor = GridBagConstraints.LINE_START;
      c.gridx = 0;
      c.gridy = 0;
      c.gridwidth = 2;
      SDPanel.add(new JLabel("This plugin creates a Shutdown node at root level. Nothing to see here."),c);
      return SDPanel;
   }

   @Override
   public String name() {
      return "Shutdown plugin";
   }

   @Override
   public void shutdown() {
      // Nothing to do here
   }

}

The complete code can be found under this topic.
el.botijo
 
Posts: 50
Joined: Thu Feb 04, 2010 9:14 pm

Re: Plugin development primer: AdditionalFolderAtRoot

Postby dradovic » Tue May 11, 2010 8:48 pm

How can the VirtualFolder be configured such that it only appears either in the audio or in the video section of the PS3 menus?
dradovic
 
Posts: 7
Joined: Tue Apr 20, 2010 8:11 pm

Re: Plugin development primer: AdditionalFolderAtRoot

Postby meskibob » Tue May 11, 2010 8:57 pm

dradovic wrote:How can the VirtualFolder be configured such that it only appears either in the audio or in the video section of the PS3 menus?

AFAIK it's not currently possible, as there's no part of the DLNA protocol for the client to tell the server which kind of files it's looking for.
I provide NO application support via PM or email, so please post your question to the forum per the Forum Rules.
meskibob
Moderator
 
Posts: 4739
Joined: Mon Jan 19, 2009 4:11 pm

Re: Plugin development primer: AdditionalFolderAtRoot

Postby tomeko » Sat May 15, 2010 8:26 pm

Sony BRAVIA TV (may be other SONY renderers, like PS3, too) supports XML tag: <av:mediaClass xmlns:av="urn:schemas-sony-com:av"> to show folder in only one XMB root (Video, Music or Pictures).
i.e folder:
Code: Select all
<container id="0$0" childCount="0" parentID="0" restricted="true" >
   <dc:title>Movies</dc:title>
   <res protocolInfo="http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_TN" >http://192.168.1.125:5001/get/0$0/thumbnail0000media</res>
   <dc:date>2010-05-11T20:13:22</dc:date>
   <upnp:class>object.container.storageFolder</upnp:class>
   <av:mediaClass xmlns:av="urn:schemas-sony-com:av">V</av:mediaClass>
</container>

will be shown only within Video XMB folder.
Media class can be: V (video), M (music) or P (pictures).
tomeko
Project Member
 
Posts: 154
Joined: Sat Jun 06, 2009 11:02 am

Re: Plugin development primer: AdditionalFolderAtRoot

Postby patters » Tue Aug 24, 2010 12:37 am

Thanks for the info tomeko. I've just spent some time tinkering with the source to get that implemented (since I own a 2009 Bravia and a 2010 Sony Bluray player) and I've discovered that the Bluray player doesn't obey this mediaClass value, but the Bravia does. It seems like they have abandoned the idea in newer devices - quite a shame.
patters
 
Posts: 97
Joined: Sun Apr 11, 2010 12:06 pm

Re: Plugin development primer: AdditionalFolderAtRoot

Postby grolschie » Tue Aug 24, 2010 3:50 am

Interestingly, Windows Media Player 11 seems to show only music related folders in the Music section of XMB, video related for the Video section, and photo related for the Photo section on the BDP-S370. I wonder if PS3MS could be configured in a similar way somehow?
grolschie
 
Posts: 263
Joined: Thu Jun 10, 2010 7:05 am

Re: Plugin development primer: AdditionalFolderAtRoot

Postby meskibob » Tue Aug 24, 2010 4:43 am

grolschie wrote:Interestingly, Windows Media Player 11 seems to show only music related folders in the Music section of XMB, video related for the Video section, and photo related for the Photo section on the BDP-S370. I wonder if PS3MS could be configured in a similar way somehow?

Interesting indeed....
Can you grab and post packet traces (eg http://www.wireshark.org/) after browsing with both WMP and PMS?
I provide NO application support via PM or email, so please post your question to the forum per the Forum Rules.
meskibob
Moderator
 
Posts: 4739
Joined: Mon Jan 19, 2009 4:11 pm

Re: Plugin development primer: AdditionalFolderAtRoot

Postby chocolateboy » Tue Aug 24, 2010 8:01 am

meskibob wrote:Interesting indeed....
Can you grab and post packet traces (eg http://www.wireshark.org/) after browsing with both WMP and PMS?


It may be related to tomeko's discovery. I tried adding a rough version of this to PMS, but couldn't get it to work with the PS3. I also tried adding "av:containerClass" (e.g. <av:containerClass>videoAllItems</av:containerClass>), with the same result.
Attachments
media_class.zip
Patch to add av:media class elements to DLNA container and item elements
(1.26 KiB) Downloaded 103 times
Last edited by chocolateboy on Tue Aug 24, 2010 12:59 pm, edited 1 time in total.
chocolateboy
Project Member
 
Posts: 2577
Joined: Wed Sep 16, 2009 10:05 am

Re: Plugin development primer: AdditionalFolderAtRoot

Postby meskibob » Tue Aug 24, 2010 12:57 pm

Yeah, I see that now. That's the problem with responding to posts on little sleep and lots of alcohol ;)
I provide NO application support via PM or email, so please post your question to the forum per the Forum Rules.
meskibob
Moderator
 
Posts: 4739
Joined: Mon Jan 19, 2009 4:11 pm

Re: Plugin development primer: AdditionalFolderAtRoot

Postby patters » Wed Aug 25, 2010 12:32 am

grolschie wrote:Interestingly, Windows Media Player 11 seems to show only music related folders in the Music section of XMB, video related for the Video section, and photo related for the Photo section on the BDP-S370. I wonder if PS3MS could be configured in a similar way somehow?

Are you sure about that? It doesn't for me. I'm using WMP11 on Windows 7 32bit and with a BDP-S370 and a Bravia 5500 (which I've verified does segregate media folders if I mod the source of PS2MS to use the av:mediaClass value).
patters
 
Posts: 97
Joined: Sun Apr 11, 2010 12:06 pm

Next

Return to Developers

Who is online

Users browsing this forum: No registered users and 3 guests