Skip to content

onLeftHandleChange & onRightHandleChange not calling in Functional Component. #18

@Ferin79

Description

@Ferin79

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions