Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/xeodou/react-native-player

Media player for React Native
https://github.com/xeodou/react-native-player

Last synced: 16 days ago
JSON representation

Media player for React Native

Awesome Lists containing this project

README

        

### React-Native-Player

> Media Player for React-Native

*Only Android support now.*

#### Integrate

##### Android

* Install via npm
`npm i react-native-player --save-dev`

* Add dependency to `android/settings.gradle`
```
...
include ':react-native-player'
project(':react-native-player').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-player/android/player')
```

* Add `android/app/build.gradle`
```
...
dependencies {
...
compile project(':react-native-player')
}
```
* Register module in `MainActivity.java`
```
import com.xeodou.rctplayer.*; // <--- import

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this);

mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new ReactPlayerManager()) // <------- here
.addPackage(new MainReactPackage())
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();

mReactRootView.startReactApplication(mReactInstanceManager, "doubanbook", null);

setContentView(mReactRootView);
}
```

#### Usage
```
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
var Subscribable = require('Subscribable');
var RCTAudio = require('react-native-player');

var doubanbook = React.createClass({

mixins: [Subscribable.Mixin],

componentWillMount: function() {
this.addListenerOn(RCTDeviceEventEmitter,
'error',
this.onError);
this.addListenerOn(RCTDeviceEventEmitter,
'end',
this.onEnd);
this.addListenerOn(RCTDeviceEventEmitter,
'ready',
this.onReady);
},

componentDidMount: function() {

},

onError: function(err) {
console.log(err)
},

onEnd: function() {
console.log("end")
},

onReady: function() {
console.log("onReady")
},

start: function() {
RCTAudio.start()
},

pause: function() {
RCTAudio.pause()
},

stop: function() {
RCTAudio.stop()
},

buttonClicked: function() {
RCTAudio.prepare("https://api.soundcloud.com/tracks/223379813/stream?client_id=f4323c6f7c0cd73d2d786a2b1cdae80c", true)
},

render: function() {
return (


Prepare!


Pause!


Start!


);
}
})

```

#### LICENSE
MIT