float duration and minor fixes
This commit is contained in:
parent
746b4234d2
commit
c81706061b
@ -28,7 +28,7 @@ class ContentManager(ModelManager):
|
||||
"name CHAR(255)",
|
||||
"type CHAR(30)",
|
||||
"location TEXT",
|
||||
"duration INTEGER",
|
||||
"duration FLOAT",
|
||||
"folder_id INTEGER",
|
||||
"created_by CHAR(255)",
|
||||
"updated_by CHAR(255)",
|
||||
|
||||
@ -9,7 +9,7 @@ from src.util.utils import str_to_enum
|
||||
|
||||
class Content:
|
||||
|
||||
def __init__(self, uuid: str = '', location: str = '', type: Union[ContentType, str] = ContentType.URL, name: str = 'Untitled', id: Optional[int] = None, duration: Optional[int] = None, created_by: Optional[str] = None, updated_by: Optional[str] = None, created_at: Optional[int] = None, updated_at: Optional[int] = None, folder_id: Optional[int] = None):
|
||||
def __init__(self, uuid: str = '', location: str = '', type: Union[ContentType, str] = ContentType.URL, name: str = 'Untitled', id: Optional[int] = None, duration: Optional[float] = None, created_by: Optional[str] = None, updated_by: Optional[str] = None, created_at: Optional[int] = None, updated_at: Optional[int] = None, folder_id: Optional[int] = None):
|
||||
self._uuid = uuid if uuid else self.generate_and_set_uuid()
|
||||
self._id = id if id else None
|
||||
self._location = location
|
||||
@ -88,11 +88,11 @@ class Content:
|
||||
self._folder_id = value
|
||||
|
||||
@property
|
||||
def duration(self) -> Optional[int]:
|
||||
def duration(self) -> Optional[float]:
|
||||
return self._duration
|
||||
|
||||
@duration.setter
|
||||
def duration(self, value: Optional[int]):
|
||||
def duration(self, value: Optional[float]):
|
||||
self._duration = value
|
||||
|
||||
@property
|
||||
|
||||
@ -10,9 +10,9 @@ def mp4_duration_with_ffprobe(filename):
|
||||
fields = json.loads(result)['streams'][0]
|
||||
|
||||
if 'tags' in fields and 'DURATION' in fields['tags']:
|
||||
return int(float(fields['tags']['DURATION']))
|
||||
return round(float(fields['tags']['DURATION']), 2)
|
||||
|
||||
if 'duration' in fields:
|
||||
return int(float(fields['duration']))
|
||||
return round(float(fields['duration']), 2)
|
||||
|
||||
return 0
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
.slide, iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: none; padding-top: 0; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; }
|
||||
.slide iframe { background: white; }
|
||||
.slide img, .slide video { height: 100%; }
|
||||
.slide video { width: 100%; height: 100%; }
|
||||
</style>
|
||||
<script type="application/javascript" src="{{ STATIC_PREFIX }}js/utils.js"></script>
|
||||
<script type="application/javascript" src="{{ STATIC_PREFIX }}js/lib/is-cron-now.js"></script>
|
||||
@ -82,6 +83,7 @@
|
||||
let curSlide = secondSlide;
|
||||
let nextSlide = firstSlide;
|
||||
let notificationItemIndex = null;
|
||||
let pausableContent = null;
|
||||
|
||||
// Functions
|
||||
const itemsLoadedProcess = function() {
|
||||
@ -126,6 +128,10 @@
|
||||
|
||||
const resume = function() {
|
||||
playState = PLAY_STATE_PLAYING;
|
||||
|
||||
if (pausableContent) {
|
||||
pausableContent.play();
|
||||
}
|
||||
};
|
||||
|
||||
const play = function() {
|
||||
@ -135,6 +141,10 @@
|
||||
const pause = function() {
|
||||
pauseClockValue = clockValue;
|
||||
playState = PLAY_STATE_PAUSE;
|
||||
|
||||
if (pausableContent) {
|
||||
pausableContent.pause();
|
||||
}
|
||||
};
|
||||
|
||||
const stop = function() {
|
||||
@ -203,7 +213,7 @@
|
||||
|
||||
let duration = item.duration;
|
||||
|
||||
if (durationsOverride[item.id]) {
|
||||
if (durationsOverride[item.id] !== undefined) {
|
||||
duration = durationsOverride[item.id];
|
||||
}
|
||||
|
||||
@ -250,17 +260,15 @@
|
||||
|
||||
if (i === curItemIndex) {
|
||||
secondsBeforeNext = accumulatedTime + safe_duration(item) - timeInCurrentLoop;
|
||||
//console.log("remaining:", secondsBeforeNext, "clock:",clockValue, curItemIndex);
|
||||
//console.log("id", item.id, "secondsBeforeNext:", secondsBeforeNext, "clock:", clockValue, "clockLoopDration", timeInCurrentLoop, "<", accumulatedTime , '+', safe_duration(item));
|
||||
}
|
||||
|
||||
if (timeInCurrentLoop < accumulatedTime + safe_duration(item)) {
|
||||
if (curItemIndex !== i) {
|
||||
//console.log('change to ', i , item.name)
|
||||
curItemIndex = i;
|
||||
|
||||
const emptySlide = getEmptySlide();
|
||||
if ((emptySlide && !hasMoveOnce) || forcePreload) {
|
||||
//console.log('init preload');
|
||||
if (!hasMoveOnce && syncWithTime) {
|
||||
if (accumulatedTime + safe_duration(item) - timeInCurrentLoop < 1) {
|
||||
// Prevent glitch when syncWithTime for first init
|
||||
@ -386,10 +394,13 @@
|
||||
delayNoisyContentJIT = lookupCurrentItem().id !== item.id ? delayNoisyContentJIT : 0;
|
||||
|
||||
video.addEventListener('loadedmetadata', function() {
|
||||
if (item.duration !== video.duration && item.delegate_duration) {
|
||||
durationsOverride[item.id] = video.duration;
|
||||
if (item.duration !== video.duration && !item.delegate_duration) {
|
||||
console.warn('Given duration ' + item.duration + 's is different from video file ' + Math.ceil(video.duration) + 's');
|
||||
}
|
||||
|
||||
if (item.delegate_duration) {
|
||||
durationsOverride[item.id] = Math.ceil(video.duration);
|
||||
}
|
||||
});
|
||||
|
||||
const autoplayLoader = function() {
|
||||
@ -401,10 +412,12 @@
|
||||
if (!previewMode) {
|
||||
setTimeout(function() {
|
||||
video.play();
|
||||
pausableContent = video;
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(autoplayLoader, delayNoisyContentJIT);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user