-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Description
onLeftHandleChange & onRightHandleChange not calling in Functional Component.
import { Audio } from "expo-av";
import * as DocumentPicker from "expo-document-picker";
import React, { useState } from "react";
import { Dimensions, Platform, Text, View } from "react-native";
import { Button } from "react-native-paper";
import Trimmer from "react-native-trimmer";
const playbackObject = new Audio.Sound();
Audio.setAudioModeAsync({
staysActiveInBackground: Platform.OS === "android" ? true : false,
playsInSilentModeIOS: Platform.OS === "ios" ? false : true,
});
const { height, width } = Dimensions.get("window");
const FirstScreen = () => {
const [leftPos, setLeftPos] = useState(0);
const [rightPos, setRightPos] = useState(15000);
const [totalDuration, setTotalDuration] = useState(0);
const loadAudio = async (uri: string) => {
try {
await playbackObject.loadAsync({
uri,
});
await playbackObject.playAsync();
} catch (error) {
console.log(error.message, "error to loading sound");
}
playbackObject.setOnPlaybackStatusUpdate((onPlaybackStatusUpdate: any) => {
setTotalDuration(onPlaybackStatusUpdate.durationMillis);
});
};
const handleDocumentPick = async () => {
DocumentPicker.getDocumentAsync({
type: "audio/*",
})
.then(async (data) => {
if (data.type === "success") {
loadAudio(data.uri);
}
})
.catch((error) => {
console.log(error);
});
};
return (
<View
style={{
display: "flex",
flex: 1,
height,
width,
justifyContent: "center",
alignItems: "center",
}}
>
<Text style={{ fontSize: 25 }}>Coming Soon...</Text>
<View>
<Trimmer
onLeftHandleChange={(event: number) => {
console.log(event);
setLeftPos(event);
}}
onRightHandleChange={(event: number) => {
console.log(event);
setRightPos(event);
}}
totalDuration={totalDuration}
trimmerLeftHandlePosition={leftPos}
trimmerRightHandlePosition={rightPos}
maxTrimDuration={15000}
/>
</View>
<Button onPress={handleDocumentPick}>Pick File</Button>
<Button onPress={() => playbackObject.playFromPositionAsync(leftPos)}>
Play
</Button>
<Button onPress={() => playbackObject.pauseAsync()}>Pause</Button>
</View>
);
};
export default FirstScreen;
Metadata
Metadata
Assignees
Labels
No labels