文件: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
},
]
组件:Track.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>
当音乐持续时间等于曲目的 DataList.json 持续时间时,我找不到任何暂停音乐的方法。
音乐应暂停,并应在指定的持续时间后恢复。任何帮助,将不胜感激!