Как сделать паузу в треке на определенное время с помощью response-native-track-player - PullRequest
0 голосов
/ 25 апреля 2020

Файл: DataList. json

[
  {
    "id": "abcd-001",
    "title": "Push Ups",
    "image": "imageOne",
    "description": "There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. ",
    "duration": 10,
    "sets": "",
    "url" : "../assets/track1.mp3"
    "break": 40
  },
  {
    "id": "abcd-002",
    "title": "Pull Ups",
    "image": "imageTwo",
    "description": "There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. ",
    "duration": 30,
    "sets": "",
    "url" : "../assets/track2.mp3"
    "break": 40
  },
]

Компонент : Трек. js

useEffect(() => {
    TrackPlayer.setupPlayer();
    TrackPlayer.updateOptions({
      stopWithApp: true,
      capabilities: [
        TrackPlayer.CAPABILITY_PLAY,
        TrackPlayer.CAPABILITY_PAUSE,
        TrackPlayer.CAPABILITY_STOP,
        TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
      ],
      compactCapabilities: [
        TrackPlayer.CAPABILITY_PLAY,
        TrackPlayer.CAPABILITY_PAUSE,
      ],
    });
  }, []);

  const togglePlayBack = async () => {
    await TrackPlayer.add({
      title: title,
      id: id,
      url: require('../assets/audio/track1.mp3'),
      artist: 'Imran Sayed',
      duration: duration,
    });
  };

     <TouchableOpacity style={styles.main}>
        <View style={styles.imgContainer}>
          <Image source={Images[`${image}`]} style={styles.image} />
        </View>
        <View style={styles.info}>
          <Text style={styles.text}> {title} </Text>
          <Text style={styles.description}> {description} </Text>
          <Text style={styles.duration}> Duration - {duration} </Text>
          <Button
            color="darkslateblue"
            title="Start"
            onPress={togglePlayBack}
          />
        </View>
      </TouchableOpacity>

Я не могу найти способ приостановить музыку c, когда продолжительность музыки c равна продолжительности трека в DataList. json.

Музыка c должна быть приостановлено и должно быть возобновлено после указанной продолжительности. Любая помощь будет оценена!

1 Ответ

0 голосов
/ 25 апреля 2020

вот решение

const progress = TrackPlayer.useTrackPlayerProgress();

const getSectionDone = () => {
  if (progress.position > 5) {
    // to ensure that music is playing
    if (progress.position === progress.duration) {
      // finished
    }
  }
};
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...