Sign up here and you can log into the forum!

Plugin: VolumeControl

The WDTVExt plugin depot. Plugins/libraries/code only

Plugin: VolumeControl   

Postby recliq » Mon Jun 14, 2010 9:28 pm

Here's a simple volume control ;)

While playing movies you can use up and down keys to increase/decrease volume.

ToDo: OSD display

VolumeControl.plugin.js
Code: Select all
traceln("VolumeControlPlugin: Start loading VolumeControl plugin");

function VolumeControlPlugin(path) {

    this.debugLogEnable = true

    this.rootPath = path;
    traceln("VolumeControlPlugin:   base path: " + this.rootPath);
    this.volume = 100
    this.volInterval = 5
    this.port = this.getPort()
    this.ip = ""
}

VolumeControlPlugin.prototype = new Plugin();
VolumeControlPlugin.prototype.constructor = VolumeControlPlugin;

VolumeControlPlugin.prototype.debugLog = function (text) {
   if (this.debugLogEnable == true) {
      if (text && text != "") {
         traceln("VolumeControlPlugin: " + text)
      }
   }
}

VolumeControlPlugin.prototype.executeCmd = function(cmd) {
   this.debugLog("[ executeCmd ]")
   this.debugLog("  cmd: " + cmd)
   var cmdOutput
   var file = new File("|" + cmd)
   if(file.open()) {
      cmdOutput = file.readln()
      file.close()
   }
   this.debugLog("  res: " + cmdOutput)
   if (cmdOutput != null) {
      return cmdOutput
   }
}

VolumeControlPlugin.prototype.getPort = function() {
   this.debugLog("[ getPort ]")
   var cmd = "netstat -lp | grep DMARender | grep LISTEN | cut -d: -f2 | awk '{print $1}'"
   var port = this.executeCmd(cmd)
   return port
}

VolumeControlPlugin.prototype.getIP = function() {
   this.debugLog("[ getIP ]")
   var cmd = "ifconfig  | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{print $1}'"
   var ip = this.executeCmd(cmd)
   return ip
}

VolumeControlPlugin.prototype.setVolume = function(volume) {
    this.debugLog("[ setVolume ] volume: " + volume)
    if (this.ip == "") {
        this.ip = this.getIP()
    }
    var post = "<s:Envelope s:encodingStyle=\\\"http://schemas.xmlsoap.org/soap/encoding/\\\" xmlns:s=\\\"http://schemas.xmlsoap.org/soap/envelope/\\\">"
    post += "<s:Body><u:SetVolume xmlns:u=\\\"urn:schemas-upnp-org:service:RenderingControl:1\\\"><InstanceID>0</InstanceID><Channel>Master</Channel>"
    post += "<DesiredVolume>" + volume + "</DesiredVolume></u:SetVolume></s:Body></s:Envelope>"
    var header = "SOAPACTION: \\\"urn:schemas-upnp-org:service:RenderingControl:1#SetVolume\\\""
    var cmd = 'wget -O /dev/null -q --post-data="' + post + '" localhost:' + this.port + '/MediaRenderer_RenderingControl/control --header="' + header + '" --bind-address=' + this.ip
    this.debugLog("  cmd: " + cmd)
    system(cmd)
}

VolumeControlPlugin.prototype.onPageKey = function(page, key) {
   if (page.markupFileName == "video_run.xml" || page.markupFileName == "audio_run.xml") {
      this.debugLog("[ onPageKey ]")
      this.debugLog("  page: " + page.markupFileName + "  key: " + key)
      if (key == 34) {
         if (this.volume < 100) {
            this.volume = this.volume + this.volInterval
            this.debugLog("  setting Volume: " + this.volume)
            this.setVolume(this.volume)
            return true
         }
      }
      if (key == 35) {
         if (this.volume > 0) {
            this.volume = this.volume - this.volInterval
            this.debugLog("  setting Volume: " + this.volume)
            this.setVolume(this.volume)
            return true
         }
      }
   }
}   

VolumeControlPlugin.instance = new VolumeControlPlugin(scriptPath);

Plugin.registerPlugin(VolumeControlPlugin.instance);

traceln("VolumeControlPlugin: End loading VolumeControl plugin");
­WDLXTV Project Maintainer
-:] If you like my contributions feel free to donate for a beer or a new flash drive. ...and always remember: RTFM! (README, FAQ, WIKI) [:-
User avatar
recliq
WDLXTV Team
 
Posts: 5513
Joined: Thu Apr 15, 2010 8:09 am
Location: Kiel, Germany

Re: Plugin: VolumeControl   

Postby thedogcow » Tue Jun 15, 2010 5:08 am

Great! Can't wait to try this! Quick question, will this conflict with other plugins, specifically media mark? I haven't had much luck running multiple plugins recently... Here's hoping :D
thedogcow
DLX'er
 
Posts: 56
Joined: Fri May 14, 2010 6:20 am

Re: Plugin: VolumeControl   

Postby thespecialist » Tue Jun 15, 2010 6:27 am

Awesome, great job !
thespecialist
Developer
 
Posts: 410
Joined: Sat Apr 24, 2010 6:59 am

Re: Plugin: VolumeControl   

Postby thespecialist » Tue Jun 15, 2010 6:43 am

Actually, just tried it and it doesn't load somehow.

As you can see I have this directory structure on my USB:
Code: Select all
# cd plugins
# ls
MediaNavigation  VolumeControl
# ls VolumeControl
VolumeControl.plugin.js


Just those 2 plugins. This is what my dmaosd log says:
Code: Select all
Start loading plugins... /tmp/mnt/
   from /tmp/mnt/
detected 2 plugins
End collecting plugins... took 4116ms
Start loading MediaNavigation plugin
End loading MediaNavigation plugin
End loading plugins... took 4183ms


And there's no trace of your Volumecontrol plugin. Any idea's ?
thespecialist
Developer
 
Posts: 410
Joined: Sat Apr 24, 2010 6:59 am

Re: Plugin: VolumeControl   

Postby recliq » Tue Jun 15, 2010 8:40 am

hm, no, i will test this as soon as i get home, will be a couple of hours though...
­WDLXTV Project Maintainer
-:] If you like my contributions feel free to donate for a beer or a new flash drive. ...and always remember: RTFM! (README, FAQ, WIKI) [:-
User avatar
recliq
WDLXTV Team
 
Posts: 5513
Joined: Thu Apr 15, 2010 8:09 am
Location: Kiel, Germany

Re: Plugin: VolumeControl   

Postby thespecialist » Tue Jun 15, 2010 9:04 am

recliq wrote:hm, no, i will test this as soon as i get home, will be a couple of hours though...

Maybe it was just me (I'm not at home right now so can't test). Anybody else tried this plugin ?
thespecialist
Developer
 
Posts: 410
Joined: Sat Apr 24, 2010 6:59 am

Re: Plugin: VolumeControl   

Postby recliq » Tue Jun 15, 2010 11:44 am

Hey TS,

there was indeed a typo in the source :oops:
I corrected the plugin in top post, there was a '+' missing in one line:
was:
Code: Select all
this.debugLog("  page: " + page.markupFileName + "  key: " key)

should be:
Code: Select all
this.debugLog("  page: " + page.markupFileName + "  key: " + key)


This caused the plugin to not be loaded...
­WDLXTV Project Maintainer
-:] If you like my contributions feel free to donate for a beer or a new flash drive. ...and always remember: RTFM! (README, FAQ, WIKI) [:-
User avatar
recliq
WDLXTV Team
 
Posts: 5513
Joined: Thu Apr 15, 2010 8:09 am
Location: Kiel, Germany

Re: Plugin: VolumeControl   

Postby thespecialist » Tue Jun 15, 2010 12:16 pm

Yup, that fixed it, great ! Now all we need is a little
recliq wrote:ToDo: OSD display
and this plugin can enter the hall of fame ;)
thespecialist
Developer
 
Posts: 410
Joined: Sat Apr 24, 2010 6:59 am

Re: Plugin: VolumeControl   

Postby recliq » Tue Jun 15, 2010 1:25 pm

I've already done this (simple Vol display, no bar display though), the problem is coexistence with other plugins.
I discussed this elswhere and wrote little lib to add content propperly (will be included as global function in next release, is included in svn) but for example the
very nice medianavigation plugin doesn't use it, so there will be problems with the display!

Here's it anyways, with simple OSD display. (not using propper content add function!)
VolumeControlOSD.plugin.js
Code: Select all
traceln("VolumeControlPlugin: Start loading VolumeControl plugin");

function VolumeControlPlugin(path) {

    this.debugLogEnable = true

    this.rootPath = path;
    traceln("VolumeControlPlugin:   base path: " + this.rootPath);
    this.volume = 100
    this.port = this.getPort()
    this.ip = ""
    //this.Content = new Content()
    this.timerRun = false
    this.showOSD = 4
    this.volInterval = 5
    this.counter = 0
}

VolumeControlPlugin.prototype = new Plugin();
VolumeControlPlugin.prototype.constructor = VolumeControlPlugin;

VolumeControlPlugin.prototype.debugLog = function (text) {
   if (this.debugLogEnable == true) {
      if (text && text != "") {
         traceln("VolumeControlPlugin: " + text)
      }
   }
}

VolumeControlPlugin.prototype.onPageCreated = function(page) {
    if (page.markupFileName == "video_run.xml" || page.markupFileName == "audio_run.xml") {
        this.debugLog("[ onPageCreated ]")
        if (!page.extraContent) {
            page.extraContent = ""
        }
        page.extraContent += <wrapper>
            <text text="@@vc_volume" x="40" y="30" w="100" h="30" fontsize="26" textcolor="0xcccccc" align="left"/>   
        </wrapper>;
        //this.Content.add(page, extraContent)
    }
}

VolumeControlPlugin.prototype.onPageTimer = function(page) {
    if (this.timerRun == true) {
        if (this.counter < this.showOSD) {
            this.counter++
        } else {
            this.counter = 0
            this.debugLog("[ onPageTimer ] clearing OSD display")
            Page.Top.setParam("vc_volume", "")
            Page.redraw(true)
            this.timerRun = false
        }
    }
}

VolumeControlPlugin.prototype.executeCmd = function(cmd) {
   this.debugLog("[ executeCmd ]")
   this.debugLog("  cmd: " + cmd)
   var cmdOutput
   var file = new File("|" + cmd)
   if(file.open()) {
      cmdOutput = file.readln()
      file.close()
   }
   this.debugLog("  res: " + cmdOutput)
   if (cmdOutput != null) {
      return cmdOutput
   }
}

VolumeControlPlugin.prototype.getPort = function() {
   this.debugLog("[ getPort ]")
   var cmd = "netstat -lp | grep DMARender | grep LISTEN | cut -d: -f2 | awk '{print $1}'"
   var port = this.executeCmd(cmd)
   return port
}

VolumeControlPlugin.prototype.getIP = function() {
   this.debugLog("[ getIP ]")
   var cmd = "ifconfig  | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{print $1}'"
   var ip = this.executeCmd(cmd)
   return ip
}

VolumeControlPlugin.prototype.setVolume = function(volume) {
    this.debugLog("[ setVolume ] volume: " + volume)
    if (this.ip == "") {
        this.ip = this.getIP()
    }
    var post = "<s:Envelope s:encodingStyle=\\\"http://schemas.xmlsoap.org/soap/encoding/\\\" xmlns:s=\\\"http://schemas.xmlsoap.org/soap/envelope/\\\">"
    post += "<s:Body><u:SetVolume xmlns:u=\\\"urn:schemas-upnp-org:service:RenderingControl:1\\\"><InstanceID>0</InstanceID><Channel>Master</Channel>"
    post += "<DesiredVolume>" + volume + "</DesiredVolume></u:SetVolume></s:Body></s:Envelope>"
    var header = "SOAPACTION: \\\"urn:schemas-upnp-org:service:RenderingControl:1#SetVolume\\\""
    var cmd = 'wget -O /dev/null -q --post-data="' + post + '" localhost:' + this.port + '/MediaRenderer_RenderingControl/control --header="' + header + '" --bind-address=' + this.ip
    this.debugLog("  cmd: " + cmd)
    system(cmd)
    var volstring = "Vol. " + volume
    Page.Top.setParam("vc_volume", volstring)
    Page.redraw(true)
    this.counter = 0
    this.timerRun = true
}

VolumeControlPlugin.prototype.onPageKey = function(page, key) {
   if (page.markupFileName == "video_run.xml" || page.markupFileName == "audio_run.xml") {
      this.debugLog("[ onPageKey ]")
      this.debugLog("  page: " + page.markupFileName + "  key: " + key)
      if (key == 34) {
         if (this.volume < 100) {
            this.volume = this.volume + this.volInterval
            this.debugLog("  setting Volume: " + this.volume)
            this.setVolume(this.volume)
            return true
         }
      }
      if (key == 35) {
         if (this.volume > 0) {
            this.volume = this.volume - this.volInterval
            this.debugLog("  setting Volume: " + this.volume)
            this.setVolume(this.volume)
            return true
         }
      }
   }
}   

VolumeControlPlugin.instance = new VolumeControlPlugin(scriptPath);

Plugin.registerPlugin(VolumeControlPlugin.instance);

traceln("VolumeControlPlugin: End loading VolumeControl plugin");



If you use MediaNavigation simple patch to coexists would be to comment out onPageCreated event in my script and add this line to the MediaNavigation XML file (inside <wrapper>):
Code: Select all
<text text="@@vc_volume" x="30" y="30" w="100" h="30" fontsize="26" textcolor="0xcccccc" align="left"/>
­WDLXTV Project Maintainer
-:] If you like my contributions feel free to donate for a beer or a new flash drive. ...and always remember: RTFM! (README, FAQ, WIKI) [:-
User avatar
recliq
WDLXTV Team
 
Posts: 5513
Joined: Thu Apr 15, 2010 8:09 am
Location: Kiel, Germany

Re: Plugin: VolumeControl   

Postby thespecialist » Tue Jun 15, 2010 1:43 pm

Haven't tried that latest version yet, just wanted to mention there's a slight problem with the previous one: if you keep holding down the down/up button, it will move the subtitle (just like it would do without your plugin).
thespecialist
Developer
 
Posts: 410
Joined: Sat Apr 24, 2010 6:59 am

Next

Return to WDTVExt plugins

Who is online

Users browsing this forum: No registered users and 2 guests