TIL: RN | react-native-sound

Lumpen·2023년 6월 11일
0

ReactNative

목록 보기
28/42

react native 에서 음성 파일을 쓰려면
react-native-sound 를 사용한다

import Sound from 'react-native-sound';

 const sound = new Sound('sound.mp3', Sound.MAIN_BUNDLE, error => {
      if (error) {
        console.log('failed to load the sound', error);
        return;
      }
      // loaded successfully
      console.log(
        'duration in seconds: ' +
          sound.getDuration() +
          'number of channels: ' +
          sound.getNumberOfChannels(),
      );

      // Play the sound with an onEnd callback
      sound.play(success => {
        if (success) {
          console.log('successfully finished playing');
        } else {
          console.log('playback failed due to audio decoding errors');
        }
      });
    });

ios 의 경우 XCode 의 project 명으로 된 최상위 폴더에 우클릭을 하여
Add Files to "[project 명]" 을 선택 후 음성 파일을 선택하여 추가한다

profile
떠돌이 생활을 하는. 실업자는 아니지만, 부랑 생활을 하는

0개의 댓글