Video player: remember volume in local storage
This commit is contained in:
parent
2698be3e12
commit
f29e01c78e
@ -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.
|
// Register our watch-progress-bookkeeping plugin.
|
||||||
videojs.registerPlugin('progressPlugin', VideoProgressPlugin);
|
videojs.registerPlugin('progressPlugin', VideoProgressPlugin);
|
||||||
|
videojs.registerPlugin('rememberVolumePlugin', RememberVolumePlugin);
|
||||||
|
@ -66,6 +66,7 @@ script(type="text/javascript").
|
|||||||
'eventsToTrack' : ['start', 'error', 'percentsPlayed']
|
'eventsToTrack' : ['start', 'error', 'percentsPlayed']
|
||||||
});
|
});
|
||||||
this.hotkeys();
|
this.hotkeys();
|
||||||
|
this.rememberVolumePlugin();
|
||||||
|
|
||||||
{% if current_user.is_authenticated %}
|
{% if current_user.is_authenticated %}
|
||||||
let fetch_progress_url = '{{ url_for("users_api.get_video_progress", video_id=node._id) }}';
|
let fetch_progress_url = '{{ url_for("users_api.get_video_progress", video_id=node._id) }}';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user