Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/daniel-hayes/react-native-simple-audio

A simple react native audio module
https://github.com/daniel-hayes/react-native-simple-audio

android audio audio-player react react-hooks react-native react-native-module swift5 typescript

Last synced: 4 days ago
JSON representation

A simple react native audio module

Awesome Lists containing this project

README

        

# react-native-simple-audio

[![codecov](https://codecov.io/gh/daniel-hayes/react-native-simple-audio/branch/master/graph/badge.svg)](https://codecov.io/gh/daniel-hayes/react-native-simple-audio)
[![npm version](https://badge.fury.io/js/react-native-simple-audio.svg)](https://badge.fury.io/js/react-native-simple-audio)

## Install
`yarn add react-native-simple-audio`

### iOS
`cd ios && pod install && cd .. # CocoaPods on iOS needs this extra step`

#### Run
`react-native run-ios`

or build manually:

1. `xed -b ios`
2. Run project in Xcode

#### NOTE ABOUT iOS USAGE
Currently, there are two other changes that need to take place before the app will properly build.
1. This package has a minimum requirement of iOS 10.0. So if you are building an application for anything lower than 10.0, you need to go into `/ios/Podfile` and change the first line to `platform :ios, '10.0'`.
2. There's a strange build issue that seems to sometimes occur with Swift based custom modules: https://stackoverflow.com/questions/52536380/why-linker-link-static-libraries-with-errors-ios/54586937#54586937 Following these steps fixes the issue. I will work on either automating this or hopefully a future version of RN will eliminate the need.

### Android

COMING SOON

## Example usage
```javascript
import {
ActivityIndicator,
Button,
View,
Text
} from 'react-native';

import { useAudioPlayer } from 'react-native-simple-audio';

export const Player = ({ url }) => {
const [player, error] = useAudioPlayer(url);

if (error) {
// handle error
console.log(error);
}

return (

{player.status.loading && !player.status.ready ? (

) : (
<>

player.seekBackwards(20)}
/>
player.seekForwards(20)}
/>

{player.status.currentTime.formatted} -
{player.status.duration.formatted}

>
)}

)
};

// Player component usage with remote url

```

## TODO
- Add full example
- Add Android functionality