javascript - 如何添加反应原生博览会 Av 搜索栏
问题描述
我正在使用 expo av 包在 react native expo cli 中构建一个音乐应用程序,我已经构建了播放和暂停等基本功能。现在我想实现搜索栏,但我不确定我该怎么做?
请看一下这段代码,请告诉我如何实现搜索栏
const Controller = () => {
const [sound, setSound] = useState();
const [isPlaying, setisPlaying] = useState();
const [currentIndex, setCurrentIndex] = useState(0);
async function playSound() {
console.log("Loading Sound");
const source = { uri: audioBookPlaylist[currentIndex].uri };
const { sound } = await Audio.Sound.createAsync(
source,
onPlaybackStatusUpdate
);
setSound(sound);
setisPlaying(true);
sound.playAsync();
console.log("song loaded");
}
useEffect(() => {
playSound();
console.log(currentIndex);
}, []);
const Playpause = async () => {
isPlaying ? await sound.pauseAsync() : await sound.playAsync();
setisPlaying(!isPlaying);
onPlaybackStatusUpdate();
// console.log(status);
};
const handleNextTrack = async () => {
if (sound) {
await sound.unloadAsync(setisPlaying(!isPlaying));
setCurrentIndex(
currentIndex + 1 > audioBookPlaylist.length - 1 ? 0 : currentIndex + 1
);
await playSound();
}
elseif;
console.log(currentIndex);
};
const handlePreviousTrack = async () => {
if (sound) {
await sound.unloadAsync(setisPlaying(false));
setCurrentIndex(
currentIndex === 0 ? audioBookPlaylist.length - 1 : currentIndex - 1
);
await playSound();
}
console.log(currentIndex);
sound ? await sound.playAsync() : null;
};
这是视图
return (
<View style={style.container}>
<View style={style.titlecontainer}>
<Text style={style.title}>The Grid: Dat Punk</Text>
<TouchableOpacity>
<CsIcons name="Like" size={30} color="white" />
</TouchableOpacity>
</View>
<Slider
style={{ width: 200, height: 40 }}
minimumValue={0}
maximumValue={1}
minimumTrackTintColor="#FFFFFF"
maximumTrackTintColor="#000000"
/>
<View style={style.controllers}>
<TouchableOpacity>
<CsIcons name="Shuffle" size={20} color="white" />
</TouchableOpacity>
<TouchableOpacity onPress={handlePreviousTrack}>
<CsIcons name="Previous" size={50} color="white" />
</TouchableOpacity>
<TouchableOpacity onPress={Playpause}>
{isPlaying ? (
<CsIcons name="Peuse" size={80} color="white" />
) : (
<CsIcons name="Play" size={80} color="white" />
)}
</TouchableOpacity>
<TouchableOpacity>
<CsIcons
name="Next"
size={50}
color="white"
onPress={handleNextTrack}
/>
</TouchableOpacity>
<TouchableOpacity>
<CsIcons name="Repeat" size={20} color="white" />
</TouchableOpacity>
</View>
<View style={style.bottomcontroller}>
<TouchableOpacity>
<CsIcons name="Share" size={20} color="white" />
</TouchableOpacity>
<TouchableOpacity>
<CsIcons name="Sort-by" size={20} color="white" />
</TouchableOpacity>
</View>
</View>
);
};
请帮我解决这个问题我该怎么做
谢谢
解决方案
推荐阅读
- node.js - 如何比较特定半径内的地理坐标
- java - RXJava2中几种方法的组合
- android - Android 5 肖像应用程序在转到最近和旋转时崩溃
- javascript - 如何在 discord.js 中检测 enmap 中的属性值?
- javascript - 无法将 nonce 属性应用于我的内联 css
- django - 将两个表的特定列数据显示到一个列表中?
- reactjs - 提交成功后关闭表单模式
- amazon-web-services - 从端点获取 JSON 文件并将它们保存到 AWS S3
- python - For 循环迭代 - Pyomo 表达式中的语法错误
- excel - 在 Excel VBA 用户窗体内的页面文本框中添加动态占位符