diff --git a/src/components/appMediaPlaybackController.ts b/src/components/appMediaPlaybackController.ts index e767280b..68b2b4ff 100644 --- a/src/components/appMediaPlaybackController.ts +++ b/src/components/appMediaPlaybackController.ts @@ -529,7 +529,10 @@ class AppMediaPlaybackController { //console.log('on media end'); - this.next(); + if(!this.next()) { + this.stop(); + rootScope.dispatchEvent('media_stop'); + } }; public toggle(play?: boolean) { @@ -658,10 +661,12 @@ class AppMediaPlaybackController { }, onJump: (item, older) => { this.playItem(item); + }, + onEmptied: () => { + rootScope.dispatchEvent('media_stop'); + this.stop(); } }); - - this.listLoader.onEmptied = this.stop; } else { this.listLoader.reset(); } @@ -691,13 +696,14 @@ class AppMediaPlaybackController { } } - public setSingleMedia(media: HTMLMediaElement, message: Message.message) { + public setSingleMedia(media?: HTMLMediaElement, message?: Message.message) { const playingMedia = this.playingMedia; const wasPlaying = this.pause(); this.willBePlayed(undefined); - this.setMedia(media, message); + if(media) this.setMedia(media, message); + else this.playingMedia = undefined; this.toggleSwitchers(false); return () => { @@ -711,7 +717,7 @@ class AppMediaPlaybackController { } } - if(this.playingMedia === media) { + if(media && this.playingMedia === media) { this.stop(); } diff --git a/src/components/chat/audio.ts b/src/components/chat/audio.ts index 01be7a86..ff8911eb 100644 --- a/src/components/chat/audio.ts +++ b/src/components/chat/audio.ts @@ -115,5 +115,9 @@ export default class ChatAudio extends PinnedContainer { this.topbar.listenerSetter.add(rootScope)('media_pause', () => { this.toggleEl.classList.remove('flip-icon'); }); + + this.topbar.listenerSetter.add(rootScope)('media_stop', () => { + this.toggle(true); + }); } } diff --git a/src/components/chat/input.ts b/src/components/chat/input.ts index f0b9d959..f844d564 100644 --- a/src/components/chat/input.ts +++ b/src/components/chat/input.ts @@ -80,6 +80,7 @@ import fixSafariStickyInputFocusing, { IS_STICKY_INPUT_BUGGED } from '../../help import { copy } from '../../helpers/object'; import PopupPeer from '../popups/peer'; import MEDIA_MIME_TYPES_SUPPORTED from '../../environment/mediaMimeTypesSupport'; +import appMediaPlaybackController from '../appMediaPlaybackController'; const RECORD_MIN_TIME = 500; const POSTING_MEDIA_NOT_ALLOWED = 'Posting media content isn\'t allowed in this group.'; @@ -176,6 +177,8 @@ export default class ChatInput { private fakePinnedControlBtn: HTMLElement; private previousQuery: string; + + private releaseMediaPlayback: () => void; constructor(private chat: Chat, private appMessagesManager: AppMessagesManager, @@ -575,6 +578,11 @@ export default class ChatInput { }; this.recorder.ondataavailable = (typedArray: Uint8Array) => { + if(this.releaseMediaPlayback) { + this.releaseMediaPlayback(); + this.releaseMediaPlayback = undefined; + } + if(this.recordingOverlayListener) { this.listenerSetter.remove(this.recordingOverlayListener); this.recordingOverlayListener = undefined; @@ -1455,7 +1463,9 @@ export default class ChatInput { this.chatInput.classList.add('is-locked'); blurActiveElement(); + this.recorder.start().then(() => { + this.releaseMediaPlayback = appMediaPlaybackController.setSingleMedia(); this.recordCanceled = false; this.chatInput.classList.add('is-recording'); diff --git a/src/helpers/searchListLoader.ts b/src/helpers/searchListLoader.ts index 85ee596f..de0c3a6e 100644 --- a/src/helpers/searchListLoader.ts +++ b/src/helpers/searchListLoader.ts @@ -85,11 +85,11 @@ export default class SearchListLoader