Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/xeodou/react-native-player
- Owner: xeodou
- Created: 2015-10-26T16:28:17.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-20T07:03:35.000Z (about 8 years ago)
- Last Synced: 2024-11-19T23:43:45.569Z (23 days ago)
- Language: Java
- Homepage:
- Size: 64.5 KB
- Stars: 84
- Watchers: 5
- Forks: 19
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-react-native - react-native-player ★81 - Media player for react-native (Components / Media)
- awesome-react-native - react-native-player ★81 - Media player for react-native (Components / Media)
- awesome-react-native - react-native-player ★81 - Media player for react-native (Components / Media)
- awesome-react-native-ui - react-native-player ★62 - Media player for react-native (Components / Media)
- awesome-react-native - react-native-player ★81 - Media player for react-native (Components / Media)
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