Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Videos now prioritize playing to the end over slideshow timer (and random sort in personal list) #142

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions BooruSlideshow/js/mvc/personal_list_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ class PersonalListController
this._view.currentVideoClickedEvent.attach(function() {
_this.currentSlideClicked();
});

this._view.currentImageStartedEvent.attach(function(){
_this.currentImageStarted();
})

this._view.currentVideoStartedEvent.attach(function(){
_this.currentVideoStarted();
})

this._view.currentVideoLoopedEvent.attach(function(){
_this.currentVideoLooped();
})

this._view.currentVideoVolumeChangedEvent.attach(function() {
_this.videoVolumeChanged();
Expand Down Expand Up @@ -129,6 +141,18 @@ class PersonalListController
this._model.setVideoMuted(videoMuted);
}

currentImageStarted(){
this._model.unlockSlideshow();
}

currentVideoStarted(){
this._model.lockSlideshow();
}

currentVideoLooped(){
this._model.unlockSlideshow();
}

firstNavButtonClicked()
{
this._model.setSlideNumberToFirst();
Expand Down
106 changes: 59 additions & 47 deletions BooruSlideshow/js/mvc/personal_list_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ class PersonalListModel{
this.isPlaying = false;
this.timer = null;
this.timerMs = 0;
this.slideshowLocked = false;

this.sitesManager = null;

this.personalList = new PersonalList();
this.filtered = false;
this.filteredPersonalList = null;
this.sortRandom = false;

this.currentSlideChangedEvent = new Event(this);
this.playingChangedEvent = new Event(this);
Expand All @@ -30,6 +32,7 @@ class PersonalListModel{
this.maxWidthUpdatedEvent = new Event(this);
this.maxHeightUpdatedEvent = new Event(this);
this.autoFitSlideUpdatedEvent = new Event(this);
this.randomSortUpdatedEvent = new Event(this);
this.personalListLoadedEvent = new Event(this);

this.dataLoader = new DataLoader(this);
Expand All @@ -53,7 +56,17 @@ class PersonalListModel{
var notTags = filterWordsAsArray.filter(tag => tag.startsWith("-"));
var notRegex = new RegExp("\\s" + notTags.join("\\s|\\s"));
notRegex = new RegExp(notRegex.toString().replace(/-/g, "").slice(1, -1) + "\\s", "gi");


filterWordsAsArray = filterWordsAsArray.filter((sortTag) => {
if (sortTag.startsWith("sort:")){
if (sortTag.startsWith("sort:random")){
this.sortRandom = true;
}
return false;
}
return true;
})

this.filtered = true;

var items = this.personalList.personalListItems.filter((item) => {
Expand Down Expand Up @@ -103,7 +116,7 @@ class PersonalListModel{
passedWild;
});

this.filteredPersonalList = new PersonalList(items)
this.filteredPersonalList = !this.sortRandom? new PersonalList(items) : new PersonalList(items.sort(() => Math.random() - 0.5));
this.currentListItem = 1
this.currentSlideChangedEvent.notify()
}
Expand All @@ -120,24 +133,27 @@ class PersonalListModel{

decreaseCurrentSlideNumber()
{

if (this.currentListItem > 1)
{
this.currentListItem--;
this.currentSlideChangedEvent.notify();
this.restartSlideshowIfOn();
}
{
this.currentListItem--;
this.currentSlideChangedEvent.notify();
this.restartSlideshowIfOn();
}

}

increaseCurrentSlideNumber()
{
let listItemCount = this.filtered ? this.filteredPersonalList.count() : this.personalList.count();

if (this.currentListItem < listItemCount)
{
this.currentListItem++;
this.currentSlideChangedEvent.notify();
this.restartSlideshowIfOn();
}
{
this.currentListItem++;
this.currentSlideChangedEvent.notify();
this.restartSlideshowIfOn();
}

}

decreaseCurrentSlideNumberByTen()
Expand Down Expand Up @@ -211,65 +227,53 @@ class PersonalListModel{

startSlideshow()
{
this.tryToStartCountdown();
this.startCountdown();

this.isPlaying = true;

this.playingChangedEvent.notify();
}

tryToStartCountdown()
{
/*if (this.sitesManager.isCurrentSlideLoaded())
{
this.startCountdown();
}
else
{
var _this = this;

this.sitesManager.runCodeWhenCurrentSlideFinishesLoading(function(){
_this.startCountdown();
});
}*/
}

/*startCountdown()
startCountdown()
{
var millisecondsPerSlide = this.secondsPerSlide * 1000;

var _this = this;
var intervalMs = 100;
var acumMs = 0;

this.timer = setTimeout(function() {
if (_this.hasNextSlide())
{
// Continue slideshow
_this.increaseCurrentSlideNumber();
}
else
{
// Loop when out of images/videos
_this.setSlideNumberToFirst();
this.timer = setInterval(function() {
if (!_this.slideshowLocked && acumMs >= millisecondsPerSlide){
clearInterval(this.timer);
if (_this.hasNextSlide())
{
// Continue slideshow
_this.increaseCurrentSlideNumber();
}
else
{
// Loop when out of images/videos
_this.setSlideNumberToFirst();
}
}
}, millisecondsPerSlide);
}*/
acumMs += intervalMs;
}, intervalMs);
}

restartSlideshowIfOn()
{

if (this.isPlaying)
{
clearTimeout(this.timer);
clearInterval(this.timer);
//this.sitesManager.clearCallbacksForPreloadingSlides();

this.tryToStartCountdown();
this.startCountdown();
}
}

pauseSlideshow()
{
clearTimeout(this.timer);
clearInterval(this.timer);
//this.sitesManager.clearCallbacksForPreloadingSlides();
//this.sitesManager.clearCallbacksForLoadingSlides();

Expand All @@ -278,6 +282,14 @@ class PersonalListModel{
this.playingChangedEvent.notify();
}

lockSlideshow(){
this.slideshowLocked = true;
}

unlockSlideshow(){
this.slideshowLocked = false;
}

getPersonalListItemCount()
{
return this.filtered ? this.filteredPersonalList.count() : this.personalList.count();
Expand Down
17 changes: 17 additions & 0 deletions BooruSlideshow/js/mvc/personal_list_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class PersonalListView
this.currentImageClickedEvent = new Event(this);
this.currentVideoClickedEvent = new Event(this);
this.currentVideoVolumeChangedEvent = new Event(this);
this.currentVideoStartedEvent = new Event(this);
this.currentImageStartedEvent = new Event(this);
this.currentVideoLoopedEvent = new Event(this);
this.filterButtonClickedEvent = new Event(this);
this.firstNavButtonClickedEvent = new Event(this);
this.previousNavButtonClickedEvent = new Event(this);
Expand Down Expand Up @@ -73,6 +76,7 @@ class PersonalListView
_this.updateAutoFitSlide();
});


this._model.personalListLoadedEvent.attach(function () {
_this.clearWarningMessage();
_this.clearInfoMessage();
Expand Down Expand Up @@ -104,6 +108,13 @@ class PersonalListView

_this.currentVideoVolumeChangedEvent.notify();
});

this.uiElements.currentVideo.addEventListener('timeupdate', () => {
if (this.uiElements.currentVideo.currentTime >= this.uiElements.currentVideo.duration - 0.5) {
this.videoLoopedOnce = true;
_this.currentVideoLoopedEvent.notify();
}
});

this.uiElements.firstNavButton.addEventListener('click', function() {
_this.firstNavButtonClickedEvent.notify();
Expand Down Expand Up @@ -223,6 +234,7 @@ class PersonalListView
this.uiElements.autoFitSlideCheckBox.addEventListener('change', function () {
_this.autoFitSlideChangedEvent.notify();
});

}

openCurrentSlide()
Expand Down Expand Up @@ -354,9 +366,12 @@ class PersonalListView

this.clearVideo();
this.updateSlideSize();

this.currentImageStartedEvent.notify();
}

displayVideo(currentSlide) {

var currentVideo = this.uiElements.currentVideo;

currentVideo.src = currentSlide.fileUrl;
Expand All @@ -366,6 +381,8 @@ class PersonalListView
this.updateSlideSize();
this.updateVideoVolume();
this.updateVideoMuted();

this.currentVideoStartedEvent.notify();
}

getVideoVolume() {
Expand Down
24 changes: 24 additions & 0 deletions BooruSlideshow/js/mvc/slideshow_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ class SlideshowController
_this.videoVolumeChanged();
});

this._view.currentImageLoadedEvent.attach(function(){
_this.currentImageStarted();
})

this._view.currentVideoLoadedEvent.attach(function(){
_this.currentVideoStarted();
})

this._view.currentVideoLoopedEvent.attach(function(){
_this.currentVideoLooped();
})

this._view.firstNavButtonClickedEvent.attach(function () {
_this.firstNavButtonClicked();
});
Expand Down Expand Up @@ -182,6 +194,18 @@ class SlideshowController
this._model.setVideoMuted(videoMuted);
}

currentImageStarted(){
this._model.unlockSlideshow();
}

currentVideoStarted(){
this._model.lockSlideshow();
}

currentVideoLooped(){
this._model.unlockSlideshow();
}

firstNavButtonClicked()
{
this._model.setSlideNumberToFirst();
Expand Down
Loading