Skip to content

Commit

Permalink
Play with RNTP buffer settings (#8328)
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondjacobson authored May 8, 2024
1 parent 9cca4d5 commit c44d02c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
10 changes: 8 additions & 2 deletions packages/mobile/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
SafeAreaProvider,
initialWindowMetrics
} from 'react-native-safe-area-context'
import TrackPlayer from 'react-native-track-player'
import TrackPlayer, { IOSCategory } from 'react-native-track-player'
import { Provider } from 'react-redux'
import { useEffectOnce } from 'react-use'
import { PersistGate } from 'redux-persist/integration/react'
Expand Down Expand Up @@ -64,7 +64,13 @@ const App = () => {
useEffectOnce(() => {
setLibs(null)
subscribeToNetworkStatusUpdates()
TrackPlayer.setupPlayer({ autoHandleInterruptions: true })
TrackPlayer.setupPlayer({
minBuffer: 0.1,
playBuffer: 0.1,
waitForBuffer: false,
autoHandleInterruptions: true,
iosCategory: IOSCategory.Playback
})
})

useEnterForeground(() => {
Expand Down
30 changes: 12 additions & 18 deletions packages/mobile/src/components/audio/AudioPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ import TrackPlayer, {
Capability,
Event,
State,
usePlaybackState,
useTrackPlayerEvents,
RepeatMode as TrackPlayerRepeatMode,
TrackType
TrackType,
PitchAlgorithm
} from 'react-native-track-player'
import { useDispatch, useSelector } from 'react-redux'
import { useAsync, usePrevious } from 'react-use'
Expand Down Expand Up @@ -166,7 +166,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)
Expand Down Expand Up @@ -609,6 +608,8 @@ export const AudioPlayer = () => {
return {
url,
type: TrackType.Default,
contentType: 'audio/mpeg',
pitchAlgorithm: PitchAlgorithm.Music,
title: track.title,
artist: trackOwner.name,
genre: track.genre,
Expand Down Expand Up @@ -652,13 +653,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
Expand All @@ -675,8 +675,7 @@ export const AudioPlayer = () => {
isCollectionMarkedForDownload,
isNotReachable,
storageNodeSelector,
nftAccessSignatureMap,
playing
nftAccessSignatureMap
])

const handleQueueIdxChange = useCallback(async () => {
Expand All @@ -694,17 +693,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()
Expand Down

0 comments on commit c44d02c

Please sign in to comment.