mirror of https://github.com/tooot-app/app
Try stopping video playback if audio issue could be fiexed
This commit is contained in:
parent
668a1dc6a6
commit
e8b3187f9e
|
@ -5,8 +5,8 @@ import { Slider } from '@sharcoux/slider'
|
||||||
import { StyleConstants } from '@utils/styles/constants'
|
import { StyleConstants } from '@utils/styles/constants'
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import { Audio } from 'expo-av'
|
import { Audio } from 'expo-av'
|
||||||
import React, { useCallback, useState } from 'react'
|
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
||||||
import { StyleSheet, View } from 'react-native'
|
import { AppState, AppStateStatus, StyleSheet, View } from 'react-native'
|
||||||
import { Blurhash } from 'react-native-blurhash'
|
import { Blurhash } from 'react-native-blurhash'
|
||||||
import AttachmentAltText from './AltText'
|
import AttachmentAltText from './AltText'
|
||||||
import attachmentAspectRatio from './aspectRatio'
|
import attachmentAspectRatio from './aspectRatio'
|
||||||
|
@ -18,12 +18,7 @@ export interface Props {
|
||||||
audio: Mastodon.AttachmentAudio
|
audio: Mastodon.AttachmentAudio
|
||||||
}
|
}
|
||||||
|
|
||||||
const AttachmentAudio: React.FC<Props> = ({
|
const AttachmentAudio: React.FC<Props> = ({ total, index, sensitiveShown, audio }) => {
|
||||||
total,
|
|
||||||
index,
|
|
||||||
sensitiveShown,
|
|
||||||
audio
|
|
||||||
}) => {
|
|
||||||
const { colors } = useTheme()
|
const { colors } = useTheme()
|
||||||
|
|
||||||
const [audioPlayer, setAudioPlayer] = useState<Audio.Sound>()
|
const [audioPlayer, setAudioPlayer] = useState<Audio.Sound>()
|
||||||
|
@ -51,6 +46,20 @@ const AttachmentAudio: React.FC<Props> = ({
|
||||||
setAudioPlaying(false)
|
setAudioPlaying(false)
|
||||||
}, [audioPlayer])
|
}, [audioPlayer])
|
||||||
|
|
||||||
|
const appState = useRef(AppState.currentState)
|
||||||
|
useEffect(() => {
|
||||||
|
const appState = AppState.addEventListener('change', _handleAppStateChange)
|
||||||
|
|
||||||
|
return () => appState.remove()
|
||||||
|
}, [])
|
||||||
|
const _handleAppStateChange = async (nextAppState: AppStateStatus) => {
|
||||||
|
if (appState.current.match(/active/) && nextAppState.match(/inactive/)) {
|
||||||
|
await audioPlayer?.stopAsync()
|
||||||
|
}
|
||||||
|
|
||||||
|
appState.current = nextAppState
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
accessibilityLabel={audio.description}
|
accessibilityLabel={audio.description}
|
||||||
|
@ -90,9 +99,7 @@ const AttachmentAudio: React.FC<Props> = ({
|
||||||
size='L'
|
size='L'
|
||||||
round
|
round
|
||||||
overlay
|
overlay
|
||||||
{...(audioPlaying
|
{...(audioPlaying ? { onPress: pauseAudio } : { onPress: playAudio })}
|
||||||
? { onPress: pauseAudio }
|
|
||||||
: { onPress: playAudio })}
|
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
@ -128,10 +135,7 @@ const AttachmentAudio: React.FC<Props> = ({
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
<AttachmentAltText
|
<AttachmentAltText sensitiveShown={sensitiveShown} text={audio.description} />
|
||||||
sensitiveShown={sensitiveShown}
|
|
||||||
text={audio.description}
|
|
||||||
/>
|
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ const AttachmentVideo: React.FC<Props> = ({
|
||||||
}, [])
|
}, [])
|
||||||
const _handleAppStateChange = async (nextAppState: AppStateStatus) => {
|
const _handleAppStateChange = async (nextAppState: AppStateStatus) => {
|
||||||
if (appState.current.match(/active/) && nextAppState.match(/inactive/)) {
|
if (appState.current.match(/active/) && nextAppState.match(/inactive/)) {
|
||||||
await videoPlayer.current?.pauseAsync()
|
await videoPlayer.current?.stopAsync()
|
||||||
} else if (gifv && appState.current.match(/background/) && nextAppState.match(/active/)) {
|
} else if (gifv && appState.current.match(/background/) && nextAppState.match(/active/)) {
|
||||||
await videoPlayer.current?.setIsMutedAsync(true)
|
await videoPlayer.current?.setIsMutedAsync(true)
|
||||||
await videoPlayer.current?.playAsync()
|
await videoPlayer.current?.playAsync()
|
||||||
|
|
|
@ -4,9 +4,9 @@ import log from './log'
|
||||||
const audio = () => {
|
const audio = () => {
|
||||||
log('log', 'audio', 'setting audio playback default options')
|
log('log', 'audio', 'setting audio playback default options')
|
||||||
Audio.setAudioModeAsync({
|
Audio.setAudioModeAsync({
|
||||||
playsInSilentModeIOS: true,
|
interruptionModeIOS: InterruptionModeIOS.DoNotMix,
|
||||||
interruptionModeIOS: InterruptionModeIOS.MixWithOthers,
|
interruptionModeAndroid: InterruptionModeAndroid.DuckOthers,
|
||||||
interruptionModeAndroid: InterruptionModeAndroid.DuckOthers
|
staysActiveInBackground: false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue