Kuldeep Tiwari
Kuldeep Tiwari

Reputation: 1

This comparison appears to be unintentional because the types 'PlaybackState | { state: undefined; }' and 'State' have no overlap

import React, { useState } from 'react'
import { View, StyleSheet, Pressable} from 'react-native'
import TrackPlayer, { State , usePlaybackState } from 'react-native-track-player';
import Icon from 'react-native-vector-icons/FontAwesome';

const ControlCenter = () => {

   const playBackState = usePlaybackState()
   const skipToNext = async () => {
    await TrackPlayer.skipToNext()
   }
   const skipToPrevious = async () => {
    await TrackPlayer.skipToPrevious()
 }
   const togglePlayback = async (playback: State) => {
   const currentTrack = await TrackPlayer.getActiveTrack();

    if (currentTrack !== null) {
    if (playback === State.Paused || playback === State.Ready) {
    await TrackPlayer.play()
  }
  else {
    await TrackPlayer.pause();
  }
}

};

    const [bgColor, setBgColor] = useState("#ff0000")
      return (
       <View style={[styles.container, { backgroundColor: `${bgColor}` }]}>
        <Pressable onPress={skipToPrevious}>
        <Icon style={styles.icon} name="step-backward" size={40} />
        </Pressable>
         <Pressable onPress={() => togglePlayback(playBackState)}>
         <Icon
           style={[styles.icon, styles.playButton]}
            name={playBackState === State.Playing ? "pause" : "play"}
          size={75}
          />
        </Pressable>
       <Pressable onPress={skipToNext}>
        <Icon style={styles.icon} name="step-forward" size={40} color="#900" />
      </Pressable>

      </View>
      )
}

I am trying to compare the values of Playback state and State.Playing but it gives error that

Argument of type 'PlaybackState | { state: undefined; }' is not assignable to parameter of type 'State'. and This comparison appears to be unintentional because the types 'PlaybackState | { state: undefined; }' and 'State' have no overlap

Upvotes: 0

Views: 207

Answers (1)

sharan kumar
sharan kumar

Reputation: 1

I've got a similar error rencently. You just need to replace "playBackState" with "playBackState.state" .

Upvotes: 0

Related Questions