From 81b639f2064d72f1231302b331c71c7bd7f9b5cf Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Wed, 15 May 2024 11:06:14 -0700 Subject: [PATCH 1/3] Revert "Fix android playback by setting default maxBuffer (#8474)" This reverts commit aa081d183fda4e144a72ef6fca182ace94e530de. --- packages/mobile/src/app/App.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/mobile/src/app/App.tsx b/packages/mobile/src/app/App.tsx index ce315d17355..32cec5b5fb2 100644 --- a/packages/mobile/src/app/App.tsx +++ b/packages/mobile/src/app/App.tsx @@ -66,8 +66,6 @@ const App = () => { subscribeToNetworkStatusUpdates() TrackPlayer.setupPlayer({ minBuffer: 0.1, - // Default value (50), but required to be set on android (crashes otherwise) - maxBuffer: 50, playBuffer: 0.1, waitForBuffer: false, autoHandleInterruptions: true, From 8a23d8cc1a302cc2dc4330ed7d207d03aad370bc Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Wed, 15 May 2024 11:07:40 -0700 Subject: [PATCH 2/3] Revert "Play with RNTP buffer settings (#8328)" This reverts commit c44d02c5afd4f362b372db6fafb20f05724335f2. --- packages/mobile/src/app/App.tsx | 10 ++----- .../src/components/audio/AudioPlayer.tsx | 30 +++++++++++-------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/mobile/src/app/App.tsx b/packages/mobile/src/app/App.tsx index 32cec5b5fb2..01a51b7812b 100644 --- a/packages/mobile/src/app/App.tsx +++ b/packages/mobile/src/app/App.tsx @@ -6,7 +6,7 @@ import { SafeAreaProvider, initialWindowMetrics } from 'react-native-safe-area-context' -import TrackPlayer, { IOSCategory } from 'react-native-track-player' +import TrackPlayer from 'react-native-track-player' import { Provider } from 'react-redux' import { useEffectOnce } from 'react-use' import { PersistGate } from 'redux-persist/integration/react' @@ -64,13 +64,7 @@ const App = () => { useEffectOnce(() => { setLibs(null) subscribeToNetworkStatusUpdates() - TrackPlayer.setupPlayer({ - minBuffer: 0.1, - playBuffer: 0.1, - waitForBuffer: false, - autoHandleInterruptions: true, - iosCategory: IOSCategory.Playback - }) + TrackPlayer.setupPlayer({ autoHandleInterruptions: true }) }) useEnterForeground(() => { diff --git a/packages/mobile/src/components/audio/AudioPlayer.tsx b/packages/mobile/src/components/audio/AudioPlayer.tsx index c5191372fb9..9673f500dd0 100644 --- a/packages/mobile/src/components/audio/AudioPlayer.tsx +++ b/packages/mobile/src/components/audio/AudioPlayer.tsx @@ -37,10 +37,10 @@ import TrackPlayer, { Capability, Event, State, + usePlaybackState, useTrackPlayerEvents, RepeatMode as TrackPlayerRepeatMode, - TrackType, - PitchAlgorithm + TrackType } from 'react-native-track-player' import { useDispatch, useSelector } from 'react-redux' import { useAsync, usePrevious } from 'react-use' @@ -166,6 +166,7 @@ export const AudioPlayer = () => { FeatureFlags.PODCAST_CONTROL_UPDATES_ENABLED, FeatureFlags.PODCAST_CONTROL_UPDATES_ENABLED_FALLBACK ) + const playbackState = usePlaybackState() const track = useSelector(getCurrentTrack) const playing = useSelector(getPlaying) const seek = useSelector(getSeek) @@ -608,8 +609,6 @@ export const AudioPlayer = () => { return { url, type: TrackType.Default, - contentType: 'audio/mpeg', - pitchAlgorithm: PitchAlgorithm.Music, title: track.title, artist: trackOwner.name, genre: track.genre, @@ -653,13 +652,14 @@ export const AudioPlayer = () => { } else { await TrackPlayer.reset() - await TrackPlayer.play() - const firstTrack = newQueueTracks[queueIndex] if (!firstTrack) return - await TrackPlayer.add(await makeTrackData(firstTrack)) + if (playing) { + await TrackPlayer.play() + } + enqueueTracksJobRef.current = enqueueTracks(newQueueTracks, queueIndex) await enqueueTracksJobRef.current enqueueTracksJobRef.current = undefined @@ -675,7 +675,8 @@ export const AudioPlayer = () => { isCollectionMarkedForDownload, isNotReachable, storageNodeSelector, - nftAccessSignatureMap + nftAccessSignatureMap, + playing ]) const handleQueueIdxChange = useCallback(async () => { @@ -693,12 +694,17 @@ export const AudioPlayer = () => { }, [queueIndex]) const handleTogglePlay = useCallback(async () => { - if (playing) { - await TrackPlayer.play() - } else { + if (playbackState.state === State.Playing && !playing) { await TrackPlayer.pause() + } else if ( + (playbackState.state === State.Paused || + playbackState.state === State.Ready || + playbackState.state === State.Stopped) && + playing + ) { + await TrackPlayer.play() } - }, [playing]) + }, [playbackState, playing]) const handleStop = useCallback(async () => { TrackPlayer.reset() From 07e4f6ddc72a6fc87e49415baf4d0bc6b0d65e79 Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Wed, 15 May 2024 11:12:35 -0700 Subject: [PATCH 3/3] Fix forward --- .../src/components/audio/AudioPlayer.tsx | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/packages/mobile/src/components/audio/AudioPlayer.tsx b/packages/mobile/src/components/audio/AudioPlayer.tsx index 9673f500dd0..17050f2dc03 100644 --- a/packages/mobile/src/components/audio/AudioPlayer.tsx +++ b/packages/mobile/src/components/audio/AudioPlayer.tsx @@ -37,7 +37,6 @@ import TrackPlayer, { Capability, Event, State, - usePlaybackState, useTrackPlayerEvents, RepeatMode as TrackPlayerRepeatMode, TrackType @@ -166,7 +165,6 @@ export const AudioPlayer = () => { FeatureFlags.PODCAST_CONTROL_UPDATES_ENABLED, FeatureFlags.PODCAST_CONTROL_UPDATES_ENABLED_FALLBACK ) - const playbackState = usePlaybackState() const track = useSelector(getCurrentTrack) const playing = useSelector(getPlaying) const seek = useSelector(getSeek) @@ -652,13 +650,12 @@ export const AudioPlayer = () => { } else { await TrackPlayer.reset() + await TrackPlayer.play() + const firstTrack = newQueueTracks[queueIndex] if (!firstTrack) return - await TrackPlayer.add(await makeTrackData(firstTrack)) - if (playing) { - await TrackPlayer.play() - } + await TrackPlayer.add(await makeTrackData(firstTrack)) enqueueTracksJobRef.current = enqueueTracks(newQueueTracks, queueIndex) await enqueueTracksJobRef.current @@ -675,8 +672,7 @@ export const AudioPlayer = () => { isCollectionMarkedForDownload, isNotReachable, storageNodeSelector, - nftAccessSignatureMap, - playing + nftAccessSignatureMap ]) const handleQueueIdxChange = useCallback(async () => { @@ -694,17 +690,12 @@ export const AudioPlayer = () => { }, [queueIndex]) const handleTogglePlay = useCallback(async () => { - if (playbackState.state === State.Playing && !playing) { - await TrackPlayer.pause() - } else if ( - (playbackState.state === State.Paused || - playbackState.state === State.Ready || - playbackState.state === State.Stopped) && - playing - ) { + if (playing) { await TrackPlayer.play() + } else { + await TrackPlayer.pause() } - }, [playbackState, playing]) + }, [playing]) const handleStop = useCallback(async () => { TrackPlayer.reset()