2021-02-02 21:51:52 +00:00
|
|
|
/**
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
2021-02-03 16:16:59 +00:00
|
|
|
import { action, computed, decorate, observable } from 'mobx';
|
2021-10-27 05:02:38 +00:00
|
|
|
import { ignore } from 'mobx-sync-lite';
|
2021-02-02 21:51:52 +00:00
|
|
|
|
2021-02-18 06:08:44 +00:00
|
|
|
import { ticksToMs } from '../utils/Time';
|
2021-02-03 16:16:59 +00:00
|
|
|
|
2021-02-02 21:51:52 +00:00
|
|
|
export default class MediaStore {
|
2021-02-18 06:08:44 +00:00
|
|
|
/**
|
|
|
|
* The MediaType being played
|
|
|
|
*/
|
2021-02-02 21:51:52 +00:00
|
|
|
type
|
2021-02-18 06:08:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* URI of the current media item
|
|
|
|
*/
|
2021-02-02 21:51:52 +00:00
|
|
|
uri
|
2021-02-18 06:08:44 +00:00
|
|
|
|
2022-03-18 19:22:25 +00:00
|
|
|
/**
|
|
|
|
* Has media playback finished
|
|
|
|
*/
|
|
|
|
isFinished = false
|
|
|
|
|
2022-05-04 16:40:11 +00:00
|
|
|
/**
|
|
|
|
* Is the media a local file (not streaming media)
|
|
|
|
*/
|
|
|
|
isLocalFile = false
|
|
|
|
|
2021-02-18 06:08:44 +00:00
|
|
|
/**
|
|
|
|
* Is the media currently playing
|
|
|
|
*/
|
|
|
|
isPlaying = false
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current playback position in ticks
|
|
|
|
*/
|
2021-02-03 16:16:59 +00:00
|
|
|
positionTicks = 0
|
2021-02-18 06:08:44 +00:00
|
|
|
|
|
|
|
/**
|
2022-03-21 13:51:06 +00:00
|
|
|
* The URI of the backdrop image of the current media item
|
2021-02-18 06:08:44 +00:00
|
|
|
*/
|
2022-03-21 13:51:06 +00:00
|
|
|
backdropUri
|
2021-02-02 21:51:52 +00:00
|
|
|
|
2021-02-18 18:32:36 +00:00
|
|
|
/**
|
|
|
|
* The player should toggle the play/pause state
|
|
|
|
*/
|
|
|
|
shouldPlayPause = false
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The player should stop playback
|
|
|
|
*/
|
|
|
|
shouldStop = false
|
|
|
|
|
2021-02-03 16:16:59 +00:00
|
|
|
get positionMillis() {
|
2021-02-18 06:08:44 +00:00
|
|
|
return ticksToMs(this.positionTicks);
|
2021-02-03 16:16:59 +00:00
|
|
|
}
|
|
|
|
|
2021-02-02 21:51:52 +00:00
|
|
|
reset() {
|
|
|
|
this.type = null;
|
|
|
|
this.uri = null;
|
2022-03-18 19:22:25 +00:00
|
|
|
this.isFinished = false;
|
2022-05-04 16:40:11 +00:00
|
|
|
this.isLocalFile = false;
|
2021-02-18 06:08:44 +00:00
|
|
|
this.isPlaying = false;
|
2021-02-03 16:16:59 +00:00
|
|
|
this.positionTicks = 0;
|
2022-03-21 13:51:06 +00:00
|
|
|
this.backdropUri = null;
|
2021-02-18 18:32:36 +00:00
|
|
|
this.shouldPlayPause = false;
|
|
|
|
this.shouldStop = false;
|
2021-02-02 21:51:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
decorate(MediaStore, {
|
|
|
|
type: [ ignore, observable ],
|
|
|
|
uri: [ ignore, observable ],
|
2022-03-18 19:22:25 +00:00
|
|
|
isFinished: [ ignore, observable ],
|
2022-05-04 16:40:11 +00:00
|
|
|
isLocalFile: [ ignore, observable ],
|
2021-02-18 06:08:44 +00:00
|
|
|
isPlaying: [ ignore, observable ],
|
2021-02-03 16:16:59 +00:00
|
|
|
positionTicks: [ ignore, observable ],
|
|
|
|
positionMillis: computed,
|
2022-03-21 13:51:06 +00:00
|
|
|
backdropUri: [ ignore, observable ],
|
2021-02-18 18:32:36 +00:00
|
|
|
shouldPlayPause: [ ignore, observable ],
|
|
|
|
shouldStop: [ ignore, observable ],
|
2021-02-02 21:51:52 +00:00
|
|
|
reset: action
|
|
|
|
});
|