React native 无法跳到下一首曲目-反应本机曲目播放器
我目前正在为我正在开发的应用程序之一创建一个播客播放器功能。然而,我遇到了一个错误,就是将数组的currentIndex更新为下一个。这是我为测试podcast plater而创建的阵列React native 无法跳到下一首曲目-反应本机曲目播放器,react-native,react-native-track-player,React Native,React Native Track Player,我目前正在为我正在开发的应用程序之一创建一个播客播放器功能。然而,我遇到了一个错误,就是将数组的currentIndex更新为下一个。这是我为测试podcast plater而创建的阵列 const [ episodes, setEpisodes ] = useState([ { id: 1, date: 'Today', title: 'Episode 10: Postcast 1', description: 'T
const [ episodes, setEpisodes ] = useState([
{
id: 1,
date: 'Today',
title: 'Episode 10: Postcast 1',
description: 'This is the podcast description',
duration: '25 mins',
image: require('../../../assets/images/podcast_image.jpg'),
audio_url: 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3',
},
{
id: 2,
date: '10/11/2020',
title: 'Episode 11: Postcast 2',
description: 'This is the podcast description',
duration: '25 mins',
image: require('../../../assets/images/podcast_image.jpg'),
audio_url: 'https://audio-previews.elements.envatousercontent.com/files/103682271/preview.mp3',
},
{
id: 3,
date: '10/11/2020',
title: 'Episode 12: Postcast 3',
description: 'This is the podcast description',
duration: '25 mins',
image: require('../../../assets/images/podcast_image.jpg'),
audio_url: 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-16.mp3',
}
]);
然后,我将currentIndex传递到下一个屏幕,以便它与剧集和播客对象一起呈现正确的播客
<TouchableOpacity onPress={() => navigation.navigate("PodcastPlayer", {
currentIndex: index,
podcast: podcast,
episodes: episodes,
})}>
var { currentIndex } = route.params;
当我跳过该曲目时,它会在控制台中记录下一个曲目,但不会在实际屏幕上更新,因此我不确定,我尝试将currentIndex
置于一个新状态中,并通过该状态进行更新,以便在单击下一步按钮后屏幕将重新渲染。但我运气不好
这是我单击下一个曲目图标时调用的函数
<TouchableOpacity style={styles.control} onPress={() => handleNextTrack()}>
<Ionicons name='ios-skip-forward' size={30} color={Colours.type.dark_blue} />
</TouchableOpacity>
handleNextTrack = async() => {
currentIndex + 1;
console.log(currentIndex);
// setNextEpisode(currentIndex);
// get the id of the current track
let trackId = await TrackPlayer.getCurrentTrack();
TrackPlayer.skip(trackId);
console.log(trackId);
}
handlenextrack()}>
handleNextTrack=async()=>{
当前指数+1;
console.log(currentIndex);
//setNextEpisode(当前索引);
//获取当前曲目的id
让trackId=wait TrackPlayer.getCurrentTrack();
TrackPlayer.skip(trackId);
console.log(trackId);
}
任何帮助都将不胜感激 在您的
handleNextTrack
功能中尝试以下操作:
currentIndex = currentIndex + 1; // instead of just currentIndex + 1;
在您的
handlenextrack
功能中尝试以下操作:
currentIndex = currentIndex + 1; // instead of just currentIndex + 1;