How to use the expo-av.Audio.Sound function in expo-av

To help you get started, we’ve selected a few expo-av examples, based on popular ways it is used in public projects.

github EvanBacon / Instagram / screens / MusicScreen.js View on Github external
async function playSongAsync({ audio }) {
  if (playingAudio) {
    await playingAudio.pauseAsync();
  }

  playingAudio = new Audio.Sound();
  try {
    await playingAudio.loadAsync(
      { uri: audio },
      { progressUpdateIntervalMillis: 100 },
    );
    await playingAudio.playAsync();
    //   soundObject.setOnPlaybackStatusUpdate(this._updateStateToStatus);
    //   const status = await soundObject.getStatusAsync();
    //   this._updateStateToStatus(status);
    //   this._sound = soundObject;
  } catch (error) {
    alert(error.message);
    // this.setState({ errorMessage: error.message });
  }
}
github SCasarotto / casarotto-chat / src / pages / Main / AudioCustom.js View on Github external
.then(() => {
					const newSoundObject = new Audio.Sound()
					newSoundObject
						.loadAsync({ uri: audio })
						.then((response) => {
							newSoundObject.setOnPlaybackStatusUpdate((statusData) => {
								const { didJustFinish } = statusData
								if (didJustFinish) {
									this.setState({ playingRecording: '', soundObject: undefined })
								}
							})
							return newSoundObject.playAsync()
						})
						.then(() => {
							this.setState({ playingRecording: _id, soundObject: newSoundObject })
						})
						.catch((error) => {
							console.log(error)
github NervJS / taro / packages / taro-rn / src / api / media / audio.ts View on Github external
constructor () {
    this.soundObject = new Audio.Sound()
    this.soundObject.setOnPlaybackStatusUpdate(this._onPlaybackStatusUpdate)
  }
github expo / expo / home / components / AudioPlayer.tsx View on Github external
useEffect(() => {
    const sound = new Audio.Sound();
    sound.setOnPlaybackStatusUpdate(status => {
      handlePlaybackStatusUpdate(sound, status);
    });

    sound.loadAsync(props.source, { progressUpdateIntervalMillis: 150 }).catch(setError);

    return () => {
      setPlayback({ isLoaded: false });
      sound.setOnPlaybackStatusUpdate(null);
      sound.unloadAsync();
    };
  }, [props.source.uri]);
github expo / expo / apps / native-component-list / src / screens / AV / AudioPlayer.tsx View on Github external
_loadSoundAsync = async (source: PlaybackSource) => {
    const soundObject = new Audio.Sound();
    try {
      await soundObject.loadAsync(source, { progressUpdateIntervalMillis: 150 });
      soundObject.setOnPlaybackStatusUpdate(this._updateStateToStatus);
      const status = await soundObject.getStatusAsync();
      this._updateStateToStatus(status);
      this._sound = soundObject;
    } catch (error) {
      this.setState({ errorMessage: error.message });
    }
  };