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

Fix mobile playback not working #8665

Merged
merged 2 commits into from
May 31, 2024
Merged
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
8 changes: 6 additions & 2 deletions packages/mobile/src/components/audio/RNVideoAudioPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const RNVideoAudioPlayer = () => {
const nftAccessSignatureMap = useSelector(getNftAccessSignatureMap)

// Queue things
const [isQueueLoaded, setIsQueueLoaded] = useState(false)
const queueIndex = useSelector(getIndex)
// const queueShuffle = useSelector(getShuffle)
const queueOrder = useSelector(getOrder)
Expand Down Expand Up @@ -423,12 +424,13 @@ export const RNVideoAudioPlayer = () => {
await enqueueTracksJobRef.current
enqueueTracksJobRef.current = undefined
} else {
setIsQueueLoaded(false)
queueRef.current = []
const firstTrack = newQueueTracks[queueIndex]
if (!firstTrack) return

queueRef.current[queueIndex] = await makeTrackData(firstTrack)

setIsQueueLoaded(true)
enqueueTracksJobRef.current = enqueueTracks(newQueueTracks, queueIndex)
await enqueueTracksJobRef.current
enqueueTracksJobRef.current = undefined
Expand Down Expand Up @@ -499,7 +501,8 @@ export const RNVideoAudioPlayer = () => {

const trackURI = useMemo(() => {
return queueRef.current[queueIndex]?.url
}, [queueIndex])
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [queueIndex, isQueueLoaded]) // need to recompute track if the queue isn't loaded

return (
trackURI && (
Expand All @@ -518,6 +521,7 @@ export const RNVideoAudioPlayer = () => {
onEnd={() => {
onNext()
}}
ignoreSilentSwitch='ignore'
onLoadStart={onLoadStart}
onLoad={onLoadFinish}
// TODO: repeating mode not implemented
Expand Down
69 changes: 38 additions & 31 deletions packages/mobile/src/components/now-playing-drawer/PlayButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { useCallback, useEffect, useState } from 'react'
import { playerActions, playerSelectors } from '@audius/common/store'
import { MIN_BUFFERING_DELAY_MS } from '@audius/common/utils'
import { useDispatch, useSelector } from 'react-redux'
import { useFeatureFlag } from '~/hooks'
import { FeatureFlags } from '~/services'

import IconPause from 'app/assets/animations/iconPause.json'
import IconPlay from 'app/assets/animations/iconPlay.json'
Expand All @@ -16,40 +18,42 @@ import { Theme } from 'app/utils/theme'
const { pause, play } = playerActions
const { getPlaying, getBuffering } = playerSelectors

const useAnimatedIcons = makeAnimations(({ palette, type }) => {
const iconColor =
type === Theme.MATRIX ? palette.background : palette.staticWhite
const useAnimatedIcons = (useRNVideoPlayer?: boolean) =>
makeAnimations(({ palette, type }) => {
const iconColor =
type === Theme.MATRIX ? palette.background : palette.staticWhite
const primaryBG = useRNVideoPlayer ? palette.accentBlue : palette.primary

const ColorizedPlayIcon = colorize(IconPlay, {
// #playpause1.Group 1.Fill 1
'layers.0.shapes.0.it.1.c.k': iconColor,
// #playpause2.Left.Fill 1
'layers.1.shapes.0.it.1.c.k': iconColor,
// #playpause2.Right.Fill 1
'layers.1.shapes.1.it.1.c.k': iconColor,
// #primaryBG.Group 2.Fill 1
'layers.2.shapes.0.it.1.c.k': palette.primary
})
const ColorizedPlayIcon = colorize(IconPlay, {
// #playpause1.Group 1.Fill 1
'layers.0.shapes.0.it.1.c.k': iconColor,
// #playpause2.Left.Fill 1
'layers.1.shapes.0.it.1.c.k': iconColor,
// #playpause2.Right.Fill 1
'layers.1.shapes.1.it.1.c.k': iconColor,
// #primaryBG.Group 2.Fill 1
'layers.2.shapes.0.it.1.c.k': primaryBG
})

const ColorizedPauseIcon = colorize(IconPause, {
// #playpause1.Group 1.Fill 1
'layers.0.shapes.0.it.1.c.k': iconColor,
// #playpause2.Left.Fill 1
'layers.1.shapes.0.it.1.c.k': iconColor,
// #playpause2.Right.Fill 1
'layers.1.shapes.1.it.1.c.k': iconColor,
// #primaryBG.Group 2.Fill 1
'layers.2.shapes.0.it.1.c.k': palette.primary
})
const ColorizedPauseIcon = colorize(IconPause, {
// #playpause1.Group 1.Fill 1
'layers.0.shapes.0.it.1.c.k': iconColor,
// #playpause2.Left.Fill 1
'layers.1.shapes.0.it.1.c.k': iconColor,
// #playpause2.Right.Fill 1
'layers.1.shapes.1.it.1.c.k': iconColor,
// #primaryBG.Group 2.Fill 1
'layers.2.shapes.0.it.1.c.k': primaryBG
})

const ColorizedSpinnerIcon = colorize(IconLoadingSpinner, {
// change color of the internal spinner
'layers.0.shapes.1.c.k': iconColor,
// change color of the background circle
'layers.1.shapes.0.it.2.c.k': palette.primary
const ColorizedSpinnerIcon = colorize(IconLoadingSpinner, {
// change color of the internal spinner
'layers.0.shapes.1.c.k': iconColor,
// change color of the background circle
'layers.1.shapes.0.it.2.c.k': primaryBG
})
return [ColorizedPlayIcon, ColorizedPauseIcon, ColorizedSpinnerIcon]
})
return [ColorizedPlayIcon, ColorizedPauseIcon, ColorizedSpinnerIcon]
})

type PlayButtonProps = Omit<AnimatedButtonProps, 'iconJSON' | 'iconIndex'>

Expand Down Expand Up @@ -78,7 +82,10 @@ export const PlayButton = ({ isActive, ...props }: PlayButtonProps) => {
}, [isBuffering])

const dispatch = useDispatch()
const animatedIcons = useAnimatedIcons()
const { isEnabled: useRNVideoPlayer } = useFeatureFlag(
FeatureFlags.USE_RN_VIDEO_PLAYER
)
const animatedIcons = useAnimatedIcons(useRNVideoPlayer)()

const handlePress = useCallback(() => {
if (isPlaying) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export const AppDrawerScreen = memo(
() => {
const [gesturesDisabled, setGesturesDisabled] = useState(false)

const useRNVideoPlayer = useFeatureFlag(FeatureFlags.USE_RN_VIDEO_PLAYER)
const { isEnabled: useRNVideoPlayer } = useFeatureFlag(
FeatureFlags.USE_RN_VIDEO_PLAYER
)

const drawerScreenOptions = useMemo(
() => ({
Expand Down