Adding seeking (math doesn't seem spot-on though)

This commit is contained in:
James Barnsley
2020-12-12 23:28:14 +13:00
parent 610ccdbb50
commit c3d7170684
5 changed files with 41 additions and 13 deletions

View File

@ -107086,6 +107086,9 @@ var MediaSession = /*#__PURE__*/function (_React$Component) {
_this = _super.call(this, props);
_defineProperty(_assertThisInitialized(_this), "actionHandler", function (action) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
seekTime = _ref.seekTime;
var _this$props = _this.props,
actions = _this$props.mopidyActions,
time_position = _this$props.time_position;
@ -107104,6 +107107,11 @@ var MediaSession = /*#__PURE__*/function (_React$Component) {
return actions.setTimePosition(time_position + 30000); // 30 seconds
}
case 'seekto':
{
return actions.setTimePosition(seekTime * 1000);
}
default:
{
return actions[action]();
@ -107155,6 +107163,9 @@ var MediaSession = /*#__PURE__*/function (_React$Component) {
mediaSession.setActionHandler('seekforward', function () {
return _this2.actionHandler('seekforward');
});
mediaSession.setActionHandler('seekto', function (position) {
return _this2.actionHandler('seekto', position);
});
mediaSession.setActionHandler('previoustrack', function () {
return _this2.actionHandler('previous');
});
@ -107164,10 +107175,11 @@ var MediaSession = /*#__PURE__*/function (_React$Component) {
}
}], [{
key: "getDerivedStateFromProps",
value: function getDerivedStateFromProps(_ref, state) {
var current_track = _ref.current_track,
stream_title = _ref.stream_title,
play_state = _ref.play_state;
value: function getDerivedStateFromProps(_ref2, state) {
var current_track = _ref2.current_track,
stream_title = _ref2.stream_title,
play_state = _ref2.play_state,
time_position = _ref2.time_position;
if (current_track) {
var title = current_track.title,
@ -107179,10 +107191,13 @@ var MediaSession = /*#__PURE__*/function (_React$Component) {
images = _current_track$images === void 0 ? {} : _current_track$images;
if (current_track.duration) {
console.log({
current_track: current_track
});
navigator.mediaSession.setPositionState({
duration: current_track.duration,
duration: current_track.duration / 1000,
playbackRate: 1,
position: 0
position: time_position / 1000
});
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -106,7 +106,7 @@
// Release details
// These are automatically injected to built HTML
var build = "1607766411";
var build = "1607768799";
var version = "3.55.3";
// Construct the script tag

View File

@ -21,11 +21,20 @@ class MediaSession extends React.Component {
mediaSession.setActionHandler('pause', () => this.actionHandler('pause'));
mediaSession.setActionHandler('seekbackward', () => this.actionHandler('seekbackward'));
mediaSession.setActionHandler('seekforward', () => this.actionHandler('seekforward'));
mediaSession.setActionHandler('seekto', (position) => this.actionHandler('seekto', position));
mediaSession.setActionHandler('previoustrack', () => this.actionHandler('previous'));
mediaSession.setActionHandler('nexttrack', () => this.actionHandler('next'));
}
static getDerivedStateFromProps({ current_track, stream_title, play_state }, state) {
static getDerivedStateFromProps(
{
current_track,
stream_title,
play_state,
time_position,
},
state,
) {
if (current_track) {
const {
title,
@ -35,10 +44,11 @@ class MediaSession extends React.Component {
} = current_track;
if (current_track.duration) {
console.log({ current_track });
navigator.mediaSession.setPositionState({
duration: current_track.duration,
duration: current_track.duration / 1000,
playbackRate: 1,
position: 0,
position: time_position / 1000,
});
}
@ -77,7 +87,7 @@ class MediaSession extends React.Component {
};
}
actionHandler = (action) => {
actionHandler = (action, { seekTime } = {}) => {
const {
mopidyActions: actions,
time_position,
@ -92,6 +102,9 @@ class MediaSession extends React.Component {
case 'seekforward': {
return actions.setTimePosition(time_position + 30000); // 30 seconds
}
case 'seekto': {
return actions.setTimePosition(seekTime * 1000);
}
default: {
return actions[action]();
}