Browse Source

Picture-in-Picture fixes

master
Eduard Kuzmenko 3 years ago
parent
commit
5d097409d7
  1. 57
      src/components/appMediaPlaybackController.ts
  2. 18
      src/components/appMediaViewerBase.ts

57
src/components/appMediaPlaybackController.ts

@ -546,16 +546,17 @@ export class AppMediaPlaybackController {
this.setMedia(media, message); this.setMedia(media, message);
const verify = (element: MediaItem) => element.mid === mid && element.peerId === peerId; const verify = (element: MediaItem) => element.mid === mid && element.peerId === peerId;
const current = this.listLoader.getCurrent(); const listLoader = this.listLoader;
const current = listLoader.getCurrent();
if(!current || !verify(current)) { if(!current || !verify(current)) {
const previous = this.listLoader.getPrevious(); const previous = listLoader.getPrevious();
let idx = previous.findIndex(verify); let idx = previous.findIndex(verify);
let jumpLength: number; let jumpLength: number;
if(idx !== -1) { if(idx !== -1) {
jumpLength = -(previous.length - idx); jumpLength = -(previous.length - idx);
} else { } else {
idx = this.listLoader.getNext().findIndex(verify); idx = listLoader.getNext().findIndex(verify);
if(idx !== -1) { if(idx !== -1) {
jumpLength = idx + 1; jumpLength = idx + 1;
} }
@ -605,9 +606,10 @@ export class AppMediaPlaybackController {
//console.log('on media end'); //console.log('on media end');
const listLoader = this.listLoader;
if(this.lockedSwitchers || if(this.lockedSwitchers ||
(!this.round && this.listLoader.current && !this.listLoader.next.length) || (!this.round && listLoader.current && !listLoader.next.length) ||
!this.listLoader.getNext().length || !listLoader.getNext().length ||
!this.next()) { !this.next()) {
this.stop(); this.stop();
rootScope.dispatchEvent('media_stop'); rootScope.dispatchEvent('media_stop');
@ -704,14 +706,15 @@ export class AppMediaPlaybackController {
}; };
public go = (length: number, dispatchJump?: boolean) => { public go = (length: number, dispatchJump?: boolean) => {
if(this.lockedSwitchers) { const listLoader = this.listLoader;
if(this.lockedSwitchers || !listLoader) {
return; return;
} }
if(this.playingMediaType === 'audio') { if(this.playingMediaType === 'audio') {
return this.listLoader.goRound(length, dispatchJump); return listLoader.goRound(length, dispatchJump);
} else { } else {
return this.listLoader.go(length, dispatchJump); return listLoader.go(length, dispatchJump);
} }
}; };
@ -772,8 +775,9 @@ export class AppMediaPlaybackController {
} }
public setTargets(current: MediaItem, prev?: MediaItem[], next?: MediaItem[]) { public setTargets(current: MediaItem, prev?: MediaItem[], next?: MediaItem[]) {
if(!this.listLoader) { let listLoader = this.listLoader;
this.listLoader = new SearchListLoader({ if(!listLoader) {
listLoader = this.listLoader = new SearchListLoader({
loadCount: 10, loadCount: 10,
loadWhenLeft: 5, loadWhenLeft: 5,
processItem: (message: Message.message) => { processItem: (message: Message.message) => {
@ -789,21 +793,21 @@ export class AppMediaPlaybackController {
} }
}); });
} else { } else {
this.listLoader.reset(); listLoader.reset();
} }
const reverse = this.searchContext.folderId !== undefined ? false : true; const reverse = this.searchContext.folderId !== undefined ? false : true;
if(prev) { if(prev) {
this.listLoader.setTargets(prev, next, reverse); listLoader.setTargets(prev, next, reverse);
} else { } else {
this.listLoader.reverse = reverse; listLoader.reverse = reverse;
} }
this.listLoader.setSearchContext(this.searchContext); listLoader.setSearchContext(this.searchContext);
this.listLoader.current = current; listLoader.current = current;
this.listLoader.load(true); listLoader.load(true);
this.listLoader.load(false); listLoader.load(false);
} }
private getPlaybackMediaTypeFromMessage(message: Message.message) { private getPlaybackMediaTypeFromMessage(message: Message.message) {
@ -860,11 +864,18 @@ export class AppMediaPlaybackController {
this.next() || this.previous(); this.next() || this.previous();
} }
} }
if(media && this.playingMedia === media) { // If it's still not cleaned
this.stop(); if(this.playingMedia === media) {
this.playingMedia = undefined;
this.playingMediaType = undefined;
} }
// I don't remember what it was for
// if(media && this.playingMedia === media) {
// this.stop();
// }
if(playPaused) { if(playPaused) {
this.play(); this.play();
} }
@ -894,8 +905,10 @@ export class AppMediaPlaybackController {
listenerSetter.removeAll(); listenerSetter.removeAll();
}, {once: true}); }, {once: true});
listenerSetter.add(video)('play', () => { listenerSetter.add(video)('play', (e) => {
this.pause(); if(this.playingMedia !== video) {
this.pause();
}
// if(this.pause()) { // if(this.pause()) {
// listenerSetter.add(video)('pause', () => { // listenerSetter.add(video)('pause', () => {
// this.play(); // this.play();

18
src/components/appMediaViewerBase.ts

@ -23,7 +23,7 @@ import { LazyLoadQueueBase } from "./lazyLoadQueue";
import ProgressivePreloader from "./preloader"; import ProgressivePreloader from "./preloader";
import SwipeHandler from "./swipeHandler"; import SwipeHandler from "./swipeHandler";
import { formatFullSentTime } from "../helpers/date"; import { formatFullSentTime } from "../helpers/date";
import appNavigationController from "./appNavigationController"; import appNavigationController, { NavigationItem } from "./appNavigationController";
import { Message } from "../layer"; import { Message } from "../layer";
import findUpClassName from "../helpers/dom/findUpClassName"; import findUpClassName from "../helpers/dom/findUpClassName";
import renderImageFromUrl, { renderImageFromUrlPromise } from "../helpers/dom/renderImageFromUrl"; import renderImageFromUrl, { renderImageFromUrlPromise } from "../helpers/dom/renderImageFromUrl";
@ -117,6 +117,7 @@ export default class AppMediaViewerBase<
protected ctrlKeyDown: boolean; protected ctrlKeyDown: boolean;
protected releaseSingleMedia: ReturnType<AppMediaPlaybackController['setSingleMedia']>; protected releaseSingleMedia: ReturnType<AppMediaPlaybackController['setSingleMedia']>;
protected navigationItem: NavigationItem;
get target() { get target() {
return this.listLoader.current; return this.listLoader.current;
@ -422,7 +423,9 @@ export default class AppMediaViewerBase<
if(this.setMoverAnimationPromise) return Promise.reject(); if(this.setMoverAnimationPromise) return Promise.reject();
appNavigationController.removeByType('media'); if(this.navigationItem) {
appNavigationController.removeItem(this.navigationItem);
}
this.lazyLoadQueue.clear(); this.lazyLoadQueue.clear();
@ -1257,7 +1260,7 @@ export default class AppMediaViewerBase<
this.toggleWholeActive(true); this.toggleWholeActive(true);
if(!IS_MOBILE_SAFARI) { if(!IS_MOBILE_SAFARI) {
appNavigationController.pushItem({ this.navigationItem = {
type: 'media', type: 'media',
onPop: (canAnimate) => { onPop: (canAnimate) => {
if(this.setMoverAnimationPromise) { if(this.setMoverAnimationPromise) {
@ -1266,7 +1269,9 @@ export default class AppMediaViewerBase<
this.close(); this.close();
} }
}); };
appNavigationController.pushItem(this.navigationItem);
} }
} }
@ -1417,6 +1422,11 @@ export default class AppMediaViewerBase<
this.toggleOverlay(!pip); this.toggleOverlay(!pip);
this.toggleGlobalListeners(!pip); this.toggleGlobalListeners(!pip);
if(this.navigationItem) {
if(pip) appNavigationController.removeItem(this.navigationItem);
else appNavigationController.pushItem(this.navigationItem);
}
if(useController) { if(useController) {
if(pip) { if(pip) {
// appMediaPlaybackController.toggleSwitchers(true); // appMediaPlaybackController.toggleSwitchers(true);

Loading…
Cancel
Save