Video player: remember volume in local storage

This commit is contained in:
Sybren A. Stüvel 2018-08-31 18:16:47 +02:00
parent 2698be3e12
commit f29e01c78e
2 changed files with 21 additions and 0 deletions

View File

@ -178,5 +178,25 @@ var VideoProgressPlugin = videojs.extend(Plugin, {
},
});
var RememberVolumePlugin = videojs.extend(Plugin, {
constructor: function(player, options) {
Plugin.call(this, player, options);
player.on('volumechange', this.on_volumechange.bind(this));
this.restore_volume();
},
restore_volume: function() {
let volume_str = localStorage.getItem('video-player-volume');
if (volume_str == null) return;
this.player.volume(1.0 * volume_str);
},
on_volumechange: function(event) {
localStorage.setItem('video-player-volume', this.player.volume());
},
});
// Register our watch-progress-bookkeeping plugin.
videojs.registerPlugin('progressPlugin', VideoProgressPlugin);
videojs.registerPlugin('rememberVolumePlugin', RememberVolumePlugin);

View File

@ -66,6 +66,7 @@ script(type="text/javascript").
'eventsToTrack' : ['start', 'error', 'percentsPlayed']
});
this.hotkeys();
this.rememberVolumePlugin();
{% if current_user.is_authenticated %}
let fetch_progress_url = '{{ url_for("users_api.get_video_progress", video_id=node._id) }}';