Audio: Add 2X button for long audio (#1905)
This commit is contained in:
parent
0355aa6d8f
commit
52fa0c8fca
@ -1,13 +1,14 @@
|
||||
import type { FC } from '../../lib/teact/teact';
|
||||
import React, { useCallback, useEffect, useMemo } from '../../lib/teact/teact';
|
||||
import { getActions, withGlobal } from '../../global';
|
||||
|
||||
import type { FC } from '../../lib/teact/teact';
|
||||
import type { AudioOrigin } from '../../types';
|
||||
import type {
|
||||
ApiAudio, ApiChat, ApiMessage, ApiUser,
|
||||
} from '../../api/types';
|
||||
|
||||
import { IS_IOS, IS_SINGLE_COLUMN_LAYOUT, IS_TOUCH_ENV } from '../../util/environment';
|
||||
import { PLAYBACK_RATE_FOR_AUDIO_MIN_DURATION } from '../../config';
|
||||
|
||||
import * as mediaLoader from '../../util/mediaLoader';
|
||||
import {
|
||||
@ -67,6 +68,7 @@ const AudioPlayer: FC<OwnProps & StateProps> = ({
|
||||
const lang = useLang();
|
||||
const { audio, voice, video } = getMessageContent(message);
|
||||
const isVoice = Boolean(voice || video);
|
||||
const shouldRenderPlaybackButton = isVoice || (audio?.duration || 0) > PLAYBACK_RATE_FOR_AUDIO_MIN_DURATION;
|
||||
const senderName = sender ? getSenderTitle(lang, sender) : undefined;
|
||||
const mediaData = mediaLoader.getFromMemory(getMessageMediaHash(message, 'inline')!) as (string | undefined);
|
||||
const mediaMetadata = useMessageMediaMetadata(message, sender, chat);
|
||||
@ -220,7 +222,7 @@ const AudioPlayer: FC<OwnProps & StateProps> = ({
|
||||
)}
|
||||
</Button>
|
||||
|
||||
{isVoice && (
|
||||
{shouldRenderPlaybackButton && (
|
||||
<Button
|
||||
round
|
||||
className={buildClassName('playback-button', playbackRate !== 1 && 'applied')}
|
||||
|
||||
@ -76,6 +76,7 @@ export const SPONSORED_MESSAGE_CACHE_MS = 300000; // 5 min
|
||||
|
||||
export const DEFAULT_VOLUME = 1;
|
||||
export const DEFAULT_PLAYBACK_RATE = 1;
|
||||
export const PLAYBACK_RATE_FOR_AUDIO_MIN_DURATION = 20 * 60; // 20 min
|
||||
|
||||
export const ANIMATION_LEVEL_MIN = 0;
|
||||
export const ANIMATION_LEVEL_MED = 1;
|
||||
|
||||
@ -3,16 +3,18 @@ import {
|
||||
} from '../lib/teact/teact';
|
||||
import { getActions, getGlobal } from '../global';
|
||||
|
||||
import { PLAYBACK_RATE_FOR_AUDIO_MIN_DURATION } from '../config';
|
||||
import type { Track, TrackId } from '../util/audioPlayer';
|
||||
import { register } from '../util/audioPlayer';
|
||||
import useEffectWithPrevDeps from './useEffectWithPrevDeps';
|
||||
import { isSafariPatchInProgress } from '../util/patchSafariProgressiveAudio';
|
||||
import useOnChange from './useOnChange';
|
||||
import type { MediaSessionHandlers } from '../util/mediaSession';
|
||||
import {
|
||||
registerMediaSession, setPlaybackState, setPositionState, updateMetadata,
|
||||
} from '../util/mediaSession';
|
||||
|
||||
import useEffectWithPrevDeps from './useEffectWithPrevDeps';
|
||||
import useOnChange from './useOnChange';
|
||||
|
||||
type Handler = (e: Event) => void;
|
||||
|
||||
const DEFAULT_SKIP_TIME = 10;
|
||||
@ -57,7 +59,8 @@ const useAudioPlayer = (
|
||||
setPlaybackState('playing');
|
||||
setVolume(getGlobal().audioPlayer.volume);
|
||||
toggleMuted(Boolean(getGlobal().audioPlayer.isMuted));
|
||||
if (trackType === 'voice') {
|
||||
const duration = proxy.duration && Number.isFinite(proxy.duration) ? proxy.duration : originalDuration;
|
||||
if (trackType === 'voice' || duration > PLAYBACK_RATE_FOR_AUDIO_MIN_DURATION) {
|
||||
setPlaybackRate(getGlobal().audioPlayer.playbackRate);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user