admin管理员组文章数量:1353261
I am using the new Expo Audio API for a react native project with expo ejected. When the audio player is used to the first time, i.e when the screen is first navigated to and before the audio is replaced, there is no error. Howevever, changing the audio or renavigating to the screen causes the error: Error: The 1st argument cannot be cast to type expo.modules.audio.AudioPlayer (received class java.lang.Integer)
.
Below is a snippet of my code
function LoadedPlayer({ book }: { book: book }) {
const bookProgress = useAppSelector(
(state) => state.books.bookProgress[book.id || ""]
);
let audioSource = {
uri: getAudioURL(book?.chapters[0].audio_id),
};
let AudioPlayer = useAudioPlayer(audioSource, 250);
const AudioPlayerStatus = useAudioPlayerStatus(AudioPlayer);
const sliderTouchableRef = useRef<View>(null);
const loadChapterToTrack = (chapterNumber: number) => {
if (!book.chapters || !book.chapters[chapterNumber] || !AudioPlayer) {
return;
}
try {
AudioPlayer.replace({
uri: getAudioURL(book.chapters[chapterNumber].audio_id),
});
} catch (e) {}
dispatch(
updateBookProgress({
bookId: book.id || "",
currentChapter: chapterNumber,
currentProgressSeconds: 0,
})
);
};
useEffect(() => {
setAudioModeAsync({
shouldPlayInBackground: true,
});
if (!bookProgress) {
dispatch(
updateBookProgress({
bookId: book.id || "",
currentChapter: 0,
currentProgressSeconds: 0,
})
);
}
(async () => {
if (!book.chapters) {
console.error("No chapters found for this book.");
return;
}
// Start playing it
AudioPlayer.play();
if (bookProgress?.currentProgressSeconds) {
AudioPlayer.seekTo(bookProgress.currentProgressSeconds);
}
})();
setTimeout(() => {
dispatch(addToCurrentlyReading(book.id || ""));
}, 5000);
setInterval(() => {
if (AudioPlayer.currentTime && AudioPlayer.duration) {
dispatch(
updateBookProgress({
bookId: book.id || "",
currentChapter: bookProgress?.currentChapter || 0,
currentProgressSeconds: AudioPlayer.currentTime,
})
);
}
}, 5000);
return () => {
AudioPlayer.release();
};
}, []);
useEffect(() => {
if (AudioPlayerStatus?.playbackState === "ended") {
console.log("ended");
loadChapterToTrack(bookProgress?.currentChapter + 1 || 0);
}
}, [AudioPlayerStatus.playbackState]);
return (
<ScreenContents />
);
}
本文标签: react nativeInternal Error while using Expo Audiounable to fixStack Overflow
版权声明:本文标题:react native - Internal Error while using Expo Audio, unable to fix - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743922900a2562419.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论