Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(UNT-T27088): external url support #56

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

nilesh-simform
Copy link
Contributor

  • added support for external URL

@nilesh-simform nilesh-simform self-assigned this Jul 16, 2024
@nilesh-simform nilesh-simform force-pushed the feature/UNT-T27088_external_url_support branch 3 times, most recently from 5067cc0 to 74f94bc Compare July 17, 2024 08:13
@kuldip-simform
Copy link
Contributor

kuldip-simform commented Jul 17, 2024

@nilesh-simform Can you please check if we are downloading audio files every time, or is it doing caching and taking file paths from cached data for the same file a second time?

If it is cached, is the downloaded media permanent or not? If yes, can we pass a file path to which we can download audio?

@nilesh-simform nilesh-simform force-pushed the feature/UNT-T27088_external_url_support branch 6 times, most recently from dc8dd51 to ac3e188 Compare September 2, 2024 07:24
@nilesh-simform
Copy link
Contributor Author

@nilesh-simform Can you please check if we are downloading audio files every time, or is it doing caching and taking file paths from cached data for the same file a second time?

If it is cached, is the downloaded media permanent or not? If yes, can we pass a file path to which we can download audio?

Yes, it is downloading audio temporarily every time, I have also added mechanism to remove temporary file on unmounting of waveform

@kuldip-simform
Copy link
Contributor

@nilesh-simform Can you please check if we are downloading audio files every time, or is it doing caching and taking file paths from cached data for the same file a second time?
If it is cached, is the downloaded media permanent or not? If yes, can we pass a file path to which we can download audio?

Yes, it is downloading audio temporarily every time, I have also added mechanism to remove temporary file on unmounting of waveform

This is fine for smaller files but for large files this does not seem right to me. @mukesh-simform Can you please check?

@hamzadar2013
Copy link

@kuldip-simform @nilesh-simform when will u merge these changes i badly need url support

@nilesh-simform nilesh-simform force-pushed the feature/UNT-T27088_external_url_support branch 3 times, most recently from 4bf11fa to d1df669 Compare September 9, 2024 06:54
@hamzadar2013
Copy link

@nilesh-simform I hope you are fine when will you merge flatlist issues changes in master from develop?

@nilesh-simform nilesh-simform force-pushed the feature/UNT-T27088_external_url_support branch 9 times, most recently from c34b0f7 to 9cd8bec Compare September 13, 2024 11:58
@mukesh-simform mukesh-simform linked an issue Sep 13, 2024 that may be closed by this pull request
@nilesh-simform nilesh-simform linked an issue Sep 16, 2024 that may be closed by this pull request
@nilesh-simform nilesh-simform linked an issue Sep 18, 2024 that may be closed by this pull request
@nilesh-simform nilesh-simform force-pushed the feature/UNT-T27088_external_url_support branch from 9cd8bec to 631e0bb Compare September 20, 2024 06:04
@SyedZawwarAhmed
Copy link

@kuldip-simform @nilesh-simform please merge these changes, I also need url support

@moeezally
Copy link

@nilesh-simform Please merge this, I need external url support for the waveform. thanks

@moeezally
Copy link

@mukesh-simform kindly review this merge, I need the external url support for the waveform asap, thanks.

@nilesh-simform nilesh-simform force-pushed the feature/UNT-T27088_external_url_support branch 4 times, most recently from 57e2faa to 57f956d Compare October 11, 2024 08:37
@moeezally
Copy link

@mukesh-simform @nilesh-simform Still waiting for the successful merge guys! :|

@moeezally
Copy link

@nilesh-simform @mukesh-simform guys can you let us know till when can we expect this PR to be merged? Will it still take considerable time? Please let us know, thanks! :)

@thetaungg
Copy link

@moeezally @SyedZawwarAhmed @hamzadar2013

If you need it urgently,

  • you can just clone the repo
  • checkout to this branch
  • build it using yarn build:local
  • extract the .tgz file it created
  • and create a patch using it.

It should work as a temporary solution until this is merged. I tested it.

@MADahab
Copy link

MADahab commented Oct 23, 2024

For any one need support for remote url urgently, there is a workaround, you can check if the url is remote, if so download it and use the local url and if not remote use the provided url
this is my code example for a component that have the waveform with play and pause button where the audioUri can be local or external url

import React, { useEffect, useRef, useState } from 'react';
import * as FileSystem from 'expo-file-system';
import {
  PlayerState,
  Waveform,
  type IWaveformRef,
} from '@simform_solutions/react-native-audio-waveform';
import { Ionicons } from '@expo/vector-icons';
import { Text, View } from 'react-native';

interface AudioPlayerProps {
  audioUri: string;
}

export const AudioPlayer = ({ audioUri }: AudioPlayerProps) => {
  const ref = useRef<IWaveformRef>(null);
  const [localUri, setLocalUri] = useState<string | null>(null);
  const [isPlaying, setIsPlaying] = useState<PlayerState | undefined>(undefined);

  useEffect(() => {
    (async () => {
      try {
        if (audioUri.startsWith('https://')) {
          // Download the audio file from the remote URL
          const fileUri = `${FileSystem.cacheDirectory}${audioUri.split('/').pop()}`;
          const { exists } = await FileSystem.getInfoAsync(fileUri);

          if (!exists) {
            // If file doesn't exist locally, download it
            await FileSystem.downloadAsync(audioUri, fileUri);
          }

          setLocalUri(fileUri);
        } else {
          // If it's a local file, use it directly
          setLocalUri(audioUri);
        }
      } catch (error) {
        console.error('Error fetching or downloading audio:', error);
      }
    })();
  }, [audioUri]);

  if (!localUri) {
    return <Text style={{ color: 'black' }}>Loading Audio</Text>;
  }

  return (
    <View
      style={{
        flex: 1,
        padding: 0,
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'center',
        height: 20,
        minWidth: 200,
        backgroundColor: '#00000000',
      }}
    >
      {isPlaying !== 'playing' ? (
        <Ionicons
          onPress={() => ref.current?.startPlayer()}
          name="play"
          size={24}
          color='black'
        />
      ) : (
        <Ionicons
          onPress={() => ref.current?.pausePlayer()}
          name="pause-circle"
          size={24}
          color='black'
        />
      )}

      <Waveform
        ref={ref}
        mode="static"
        path={localUri}
        candleSpace={1}
        scrubColor="grey"
        candleHeightScale={10}
        waveColor='black'
        containerStyle={{ padding: 0, height: 40, flex: 1 }}
        onPanStateChange={(isMoving) => console.log(isMoving)}
        onPlayerStateChange={(playerState) => setIsPlaying(playerState)}
      />
    </View>
  );
};

@Bayramito
Copy link

Is it possible to add .wav file support too @nilesh-simform ?

@prince-d-simform prince-d-simform force-pushed the feature/UNT-T27088_external_url_support branch from 57f956d to 49bf4dd Compare November 14, 2024 06:35
@nilesh-simform nilesh-simform force-pushed the feature/UNT-T27088_external_url_support branch 6 times, most recently from a0147be to b9b682a Compare November 22, 2024 12:56
@nilesh-simform nilesh-simform force-pushed the feature/UNT-T27088_external_url_support branch from b9b682a to bf827f8 Compare November 25, 2024 13:30
@pradipbhanderi
Copy link

@kuldip-simform @nilesh-simform please merge these changes, I also need url support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
9 participants