Skip to content

Commit 5067cc0

Browse files
feat(UNT-T27088): external url support
1 parent 9c3efa7 commit 5067cc0

File tree

6 files changed

+131
-50
lines changed

6 files changed

+131
-50
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ You can check out the full example at [Example](./example/src/App.tsx).
127127
| mode\* | - ||| 'live' or 'static' | Type of waveform. It can be either `static` for the resource file or `live` if you want to record audio |
128128
| ref\* | - ||| IWaveformRef | Type of ref provided to waveform component. If waveform mode is `static`, some methods from ref will throw error and same for `live`.<br> Check [IWaveformRef](#iwaveformref-methods) for more details about which methods these refs provides. |
129129
| path\* | - ||| string | Used for `static` type. It is the resource path of an audio source file. |
130+
| isExternalUrl | false ||| boolean | Used for `static` type. If the resource path of an audio file is a URL, then pass true; otherwise, pass false. |
130131
| candleSpace | 2 ||| number | Space between two candlesticks of waveform |
131132
| candleWidth | 5 ||| number | Width of single candlestick of waveform |
132133
| candleHeightScale | 3 ||| number | Scaling height of candlestick of waveform |
@@ -138,6 +139,8 @@ You can check out the full example at [Example](./example/src/App.tsx).
138139
| onRecorderStateChange | - ||| ( recorderState : RecorderState ) => void | callback function which returns the recorder state whenever the recorder state changes. Check RecorderState for more details |
139140
| onCurrentProgressChange | - ||| ( currentProgress : number, songDuration: number ) => void | callback function, which returns current progress of audio and total song duration. |
140141
| onChangeWaveformLoadState | - ||| ( state : boolean ) => void | callback function which returns the loading state of waveform candlestick. |
142+
| onDownloadStateChange | - ||| ( state : boolean ) => void | A callback function that returns the loading state of a file download from an external URL. |
143+
| onDownloadProgressChange | - ||| ( currentProgress : number ) => void | Used when isExternalUrl is true; a callback function that returns the current progress of a file download from an external URL |
141144
| onError | - ||| ( error : Error ) => void | callback function which returns the error for static audio waveform |
142145

143146
##### Know more about [ViewStyle](https://reactnative.dev/docs/view-style-props), [PlayerState](#playerstate), and [RecorderState](#recorderstate)

example/src/App.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ const ListItem = React.memo(
4141
currentPlaying,
4242
setCurrentPlaying,
4343
onPanStateChange,
44+
isExternalUrl = false,
4445
}: {
4546
item: ListItem;
4647
currentPlaying: string;
4748
setCurrentPlaying: Dispatch<SetStateAction<string>>;
4849
onPanStateChange: (value: boolean) => void;
50+
isExternalUrl?: boolean;
4951
}) => {
5052
const ref = useRef<IWaveformRef>(null);
5153
const [playerState, setPlayerState] = useState(PlayerState.stopped);
@@ -116,10 +118,17 @@ const ListItem = React.memo(
116118
setCurrentPlaying('');
117119
}
118120
}}
121+
isExternalUrl={isExternalUrl}
119122
onPanStateChange={onPanStateChange}
120123
onError={error => {
121124
console.log(error, 'we are in example');
122125
}}
126+
onDownloadStateChange={state => {
127+
console.log('Download State', state);
128+
}}
129+
onDownloadProgressChange={progress => {
130+
console.log('Download Progress', `${progress}%`);
131+
}}
123132
onCurrentProgressChange={(currentProgress, songDuration) => {
124133
console.log(
125134
'currentProgress ',
@@ -241,6 +250,7 @@ const AppContainer = () => {
241250
currentPlaying={currentPlaying}
242251
setCurrentPlaying={setCurrentPlaying}
243252
item={item}
253+
isExternalUrl={item.isExternalUrl}
244254
onPanStateChange={value => setShouldScroll(!value)}
245255
/>
246256
))}

example/src/constants/Audios.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { globalMetrics } from '../../src/theme';
55
export interface ListItem {
66
fromCurrentUser: boolean;
77
path: string;
8+
isExternalUrl?: boolean;
89
}
910

1011
/**
@@ -54,15 +55,28 @@ const audioAssetArray = [
5455
'file_example_mp3_15s.mp3',
5556
];
5657

58+
const externalAudioAssetArray = [
59+
'https://codeskulptor-demos.commondatastorage.googleapis.com/GalaxyInvaders/theme_01.mp3',
60+
'https://codeskulptor-demos.commondatastorage.googleapis.com/pang/paza-moduless.mp3',
61+
];
62+
5763
copyFilesToAndroidResources();
5864

5965
/**
6066
* List of file objects with information about the files.
6167
* @type {ListItem[]}
6268
*/
63-
export const audioListArray: ListItem[] = audioAssetArray.map(
69+
const audioList: ListItem[] = audioAssetArray.map((value, index) => ({
70+
fromCurrentUser: index % 2 !== 0,
71+
path: `${filePath}/${value}`,
72+
}));
73+
74+
const externalAudioList: ListItem[] = externalAudioAssetArray.map(
6475
(value, index) => ({
6576
fromCurrentUser: index % 2 !== 0,
66-
path: `${filePath}/${value}`,
77+
path: value,
78+
isExternalUrl: true,
6779
})
6880
);
81+
82+
export const audioListArray: ListItem[] = [...audioList, ...externalAudioList];

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
]
111111
},
112112
"dependencies": {
113-
"lodash": "^4.17.21"
113+
"lodash": "^4.17.21",
114+
"rn-fetch-blob": "^0.12.0"
114115
}
115-
}
116+
}

0 commit comments

Comments
 (0)