Skip to content

Commit

Permalink
Add action to change playback rate/speed
Browse files Browse the repository at this point in the history
  • Loading branch information
istnv committed Jul 6, 2023
1 parent 995d772 commit c2440cc
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 21 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,9 @@ See HELP.md and LICENSE

**V2.2.0**
* Add volume and playlist count variables

**V2.2.1**
* Don't strip +/- from volume adjustment

**V2.3.0**
* Add actions to adjust playback speed/rate
66 changes: 50 additions & 16 deletions actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export function GetActionDefinitions(self) {
}
// force an update if command sent while VLC stopped
self.PollNow = true

}

const getTheClip = async (action) => {
Expand Down Expand Up @@ -73,24 +72,30 @@ export function GetActionDefinitions(self) {
},
pause: {
name: 'Pause / Resume',
options: [ {
type: 'dropdown',
label: 'Which action?',
id: 'opt',
default: '2',
choices: [
{ id: '0', label: 'Pause' },
{ id: '1', label: 'Resume' },
{ id: '2', label: 'Toggle' },
],
} ],
options: [
{
type: 'dropdown',
label: 'Which action?',
id: 'opt',
default: '2',
choices: [
{ id: '0', label: 'Pause' },
{ id: '1', label: 'Resume' },
{ id: '2', label: 'Toggle' },
],
},
],
callback: async (action) => {
if (self.PlayState==1) { // paused
if (action.options?.opt != 0) { // action is resume/toggle
if (self.PlayState == 1) {
// paused
if (action.options?.opt != 0) {
// action is resume/toggle
await sendCommand('pl_pause')
}
} else if (self.PlayState==2) { // playing
if (action.options?.opt != 1) { // action is pause/toggle
} else if (self.PlayState == 2) {
// playing
if (action.options?.opt != 1) {
// action is pause/toggle
await sendCommand('pl_pause')
}
} // else ignore
Expand Down Expand Up @@ -212,6 +217,35 @@ export function GetActionDefinitions(self) {
})
},
},
rate: {
name: 'Set Playback Rate',
options: [
{
type: 'textinput',
label: 'Value',
id: 'rate',
useVariables: true,
default: 100,
},
],
callback: async (action) => {
let rate = await self.parseVariablesInString(action.options.rate)
const adj = ['+', '-'].includes(rate.slice(0, 1)) ? rate.slice(0, 1) : ''

if (adj == '') {
rate = rate / 100
} else {
rate = self.vlcRate + parseInt(rate) / 100
if (Math.abs(rate - 1) < 0.001) {
rate = 1
}
}

await sendCommand('rate', {
val: rate,
})
},
},
full: {
name: 'Full Screen',
options: [
Expand Down
17 changes: 13 additions & 4 deletions companion/HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ VLC is a free and open source cross-platform multimedia player and framework tha

You can find it here: <a href="https://www.videolan.org/vlc/index.html" title="VLC">videolan.org</a>

--------
Contributions for maintenance and development of this open source module are always welcome
https://github.com/sponsors/istnv

--------
# *IMPORTANT UPDATE!*
**If you used this module prior to the feedback and variables version, the Play ID has changed!**
The prior versions *sometimes* worked by starting the playlist at number 3. This version retrieves the
Expand Down Expand Up @@ -34,7 +38,7 @@ Action | Description
**Play ID** | Play a specific item from the playlist. If ID does not exist, this command acts like a simple **Play** command.
**Stop** | Stop playback
**Pause / Resume** | Toggle pause. If state is 'stopped' then play current item. If no current item then play the 1st item.
**Seek To** | Set playback to a particular position in the current item. See below for options.
**Seek To** | Set playback to a particular position in the current item. See below for options. **
**Next** | Jump to next item
**Previous** | Jump to previous item
**Full Screen** | Toggle full screen
Expand All @@ -43,13 +47,16 @@ Action | Description
**Repeat** | Toggle item repeat mode (cancels loop mode)
**Clear Playlist** | Clear all items from Playlist
**Delete ID** | Delete item with ID from Playlist
**Volume** | Adjust VLC playback volume. Can be Absolute (0-320) or Relative (+1, -5)
**Add Item** | Add item to Playlist
**Add and Play** | Add item to Playlist and Play
**Volume** | Adjust VLC playback volume. Can be Absolute (0-320) or Relative (+1, -5) **
**Set Playback Rate** | Set or adjust playback playback rate. Must be larger than 0. 100 is normal speed. Add +/- to adjust by percentage. **
**Add Item** | Add item to Playlist **
**Add and Play** | Add item to Playlist and Play **
**Delete ID** | Delete a specific item from the playlist

*Note:* All toggle style actions have options to set On, Off, or Toggle

** These actions accept dynamic variables for their options.

>\
>The **Seek To *Where*** option accepts values of the form:\
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[+ or -][{int}{H or h}:][{int}{M or m or '}:][{int}{nothing or S or s or "}] or [+ or -]{int}%\
Expand Down Expand Up @@ -83,6 +90,7 @@ Variable | Description
**$(INSTANCENAME:v_num)** | Number of items loaded in current playlist
**$(INSTANCENAME:vol)** | Current volume value (0-320)
**$(INSTANCENAME:volp)** | Current volume percent (Value of 256 is 100%)
**$(INSTANCENAME:rate)** | Current playback speed as percent

To use these, replace INSTANCENAME with the label/name of your connection label

Expand All @@ -107,3 +115,4 @@ On the Main Interfaces-->Lua page, set the password for Companion access.
![setup2](images/VLCSetup2.png "Setup2")

***Note:** VLC must be closed and restarted for the password to take effect.*

7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ class VlcInstance extends InstanceBase {
volp: Math.round(((this.vlcVolume * 100.0) + Number.EPSILON) / 256.0),
})
}
if (this.vlcRate != pbInfo.rate) {
this.vlcRate = pbInfo.rate
this.setVariableValues({
rate: Math.round((this.vlcRate * 100))
})

}
///
/// pb vars and feedback here
///
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "videolan-vlc",
"version": "2.2.1",
"version": "2.3.0",
"main": "index.js",
"type": "module",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions variable.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,9 @@ export function GetVariableDefinitions() {
name: 'Current playback volume %',
variableId: 'volp',
},
{
name: 'Current playback speed %',
variableId: 'rate',
}
]
}

0 comments on commit c2440cc

Please sign in to comment.