Skip to content

Commit

Permalink
Add MediaPlayer.setCanRepeat/setRepeatState
Browse files Browse the repository at this point in the history
Issue: #21

Signed-off-by: Jiří Janoušek <[email protected]>
  • Loading branch information
jiri-janousek committed Sep 17, 2018
1 parent cbe5101 commit be08264
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
10 changes: 5 additions & 5 deletions doc/pages/apps/mediaplayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,14 @@ WebApp._onActionActivated = function (emitter, name, param) {
Repeat Status
-------------

Since **Nuvola 4.12.86**, it is possible to integrate the **repeat status**.
Since **Nuvola 4.12.92**, it is possible to integrate the **repeat status**.

* It is implemented as an action [PlayerAction.REPEAT](apiref>Nuvola.PlayerAction.REPEAT) with three states:
[PlayerRepeat.NONE](apiref>Nuvola.PlayerRepeat.NONE) (default, don't repeat),
[PlayerRepeat.TRACK](apiref>Nuvola.PlayerRepeat.TRACK) (repeat a single track), and
[PlayerRepeat.PLAYLIST](apiref>Nuvola.PlayerRepeat.PLAYLIST) (repeat the whole playlist).
* Use [Actions.updateEnabledFlag](apiref>Nuvola.Actions.updateEnabledFlag) to enable the action
and [Actions.updateState](apiref>Nuvola.Actions.updateState) to update the current state.
* Use [MediaPlayer.setCanRepeat](apiref>Nuvola.MediaPlayer.setCanRepeat) to enable the action
and [MediaPlayer.setRepeatState](apiref>Nuvola.MediaPlayer.setRepeatState) to update the current state.
* The [PlayerAction.REPEAT](apiref>Nuvola.PlayerAction) is emitted whenever the repeat status is changed remotely.
The parameter is the new repeat status.

Expand All @@ -446,8 +446,8 @@ WebApp._setRepeat = function (repeat) {
WebApp.update = function () {
...
var repeat = this._getRepeat()
Nuvola.actions.updateEnabledFlag(PlayerAction.REPEAT, repeat !== null)
Nuvola.actions.updateState(PlayerAction.REPEAT, repeat || 0)
player.setCanRepeat(repeat !== null)
player.setRepeatState(repeat)
...
}

Expand Down
24 changes: 24 additions & 0 deletions src/mainjs/mediaplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,30 @@ MediaPlayer.setShuffleState = function (shuffle) {
Nuvola.actions.updateState(PlayerAction.SHUFFLE, !!shuffle)
}

/**
* Set whether it is possible to repeat a track or a playlist.
*
* If the argument is same as in the previous call, this method does nothing.
*
* @since Nuvola 4.13
*
* @param Boolean canRepeat true if the repeat state can be changed.
*/
MediaPlayer.setCanRepeat = function (canRepeat) {
Nuvola.actions.updateEnabledFlag(PlayerAction.REPEAT, canRepeat)
}

/**
* Set the current repeat state.
*
* If the current state is same as the previous one, this method does nothing.
*
* @param PlayerRepeat repeat The current repeat state.
*/
MediaPlayer.setRepeatState = function (repeat) {
Nuvola.actions.updateState(PlayerAction.REPEAT, 1 * (repeat || 0))
}

/**
* Add actions for media player capabilities
*
Expand Down

0 comments on commit be08264

Please sign in to comment.