@@ -63,34 +63,41 @@ const RenderListItem = React.memo(
6363 const [ isLoading , setIsLoading ] = useState ( true ) ;
6464
6565 const handlePlayPauseAction = async ( ) => {
66- let currentPlayer = currentPlayingRef ?. current ;
67-
68- // If no player or if current player is stopped just start it!
66+ // If we are recording do nothing
6967 if (
70- currentPlayer == null ||
71- currentPlayer . currentState === PlayerState . stopped
68+ currentPlayingRef ?. current ?. currentState === RecorderState . recording
7269 ) {
70+ return ;
71+ }
72+
73+ const startNewPlayer = async ( ) => {
7374 currentPlayingRef = ref ;
74- await currentPlayingRef . current ?. startPlayer ( {
75- finishMode : FinishMode . stop ,
76- } ) ;
77- } else {
78- // If we are recording do nothing
79- if ( currentPlayer . currentState === RecorderState . recording ) {
80- return ;
75+ if ( ref . current ?. currentState === PlayerState . paused ) {
76+ await ref . current ?. resumePlayer ( ) ;
77+ } else {
78+ await ref . current ?. startPlayer ( {
79+ finishMode : FinishMode . stop ,
80+ } ) ;
8181 }
82+ } ;
8283
84+ // If no player or if current player is stopped just start the new player!
85+ if (
86+ currentPlayingRef == null ||
87+ [ PlayerState . stopped , PlayerState . paused ] . includes (
88+ currentPlayingRef ?. current ?. currentState as PlayerState
89+ )
90+ ) {
91+ await startNewPlayer ( ) ;
92+ } else {
8393 // Pause current player if it was playing
84- if ( currentPlayer . currentState === PlayerState . playing ) {
94+ if ( currentPlayingRef ?. current ? .currentState === PlayerState . playing ) {
8595 await currentPlayingRef ?. current ?. pausePlayer ( ) ;
8696 }
8797
8898 // Start player when it is a different one!
89- if ( currentPlayer . playerKey ( ) !== ref ?. current ?. playerKey ( ) ) {
90- currentPlayingRef = ref ;
91- await currentPlayingRef . current ?. startPlayer ( {
92- finishMode : FinishMode . stop ,
93- } ) ;
99+ if ( currentPlayingRef ?. current ?. playerKey !== ref ?. current ?. playerKey ) {
100+ await startNewPlayer ( ) ;
94101 }
95102 }
96103 } ;
0 commit comments