Commit 9a936c9e authored by Andrew Jack's avatar Andrew Jack Committed by Matt Apperson
Browse files

ExoPlayer (#426)

parent cd53e389
Loading
Loading
Loading
Loading
+2 −1
Changes for README.md: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -150,6 +150,7 @@ using System.Collections.Generic;
       onProgress={this.setTime}      // Callback every ~250ms with currentTime
       onEnd={this.onEnd}             // Callback when playback finishes
       onError={this.videoError}      // Callback when video cannot be loaded
       onBuffer={this.onBuffer} // Callback when remote video is buffering
       style={styles.backgroundVideo} />

// Later to trigger fullscreen
@@ -250,7 +251,7 @@ Toggles a fullscreen player. Access using a ref to the component.

- [ ] Add support for captions
- [ ] Add support for playing multiple videos in a sequence (will interfere with current `repeat` implementation)
- [ ] Callback to get buffering progress for remote videos
- [x] Callback to get buffering progress for remote videos
- [ ] Bring API closer to HTML5 `<Video>` [reference](http://devdocs.io/html/element/video)

[1]: https://github.com/brentvatne/react-native-login/blob/56c47a5d1e23781e86e19b27e10427fd6391f666/App/Screens/UserInfoScreen.js#L32-L35
+27 −1
Changes for Video.js: 27 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -131,6 +131,24 @@ export default class Video extends Component {
    }
  };

  _onAudioBecomingNoisy = () => {
    if (this.props.onAudioBecomingNoisy) {
      this.props.onAudioBecomingNoisy();
    }
  };

  _onAudioFocusChanged = (event) => {
    if (this.props.onAudioFocusChanged) {
      this.props.onAudioFocusChanged(event.nativeEvent);
    }
  };

  _onBuffer = (event) => {
    if (this.props.onBuffer) {
      this.props.onBuffer(event.nativeEvent);
    }
  };

  render() {
    const resizeMode = this.props.resizeMode;
    const source = resolveAssetSource(this.props.source) || {};
@@ -162,7 +180,7 @@ export default class Video extends Component {
        uri,
        isNetwork,
        isAsset,
        type: source.type || 'mp4',
        type: source.type,
        mainVer: source.mainVer || 0,
        patchVer: source.patchVer || 0,
      },
@@ -172,6 +190,7 @@ export default class Video extends Component {
      onVideoProgress: this._onProgress,
      onVideoSeek: this._onSeek,
      onVideoEnd: this._onEnd,
      onVideoBuffer: this._onBuffer,
      onVideoFullscreenPlayerWillPresent: this._onFullscreenPlayerWillPresent,
      onVideoFullscreenPlayerDidPresent: this._onFullscreenPlayerDidPresent,
      onVideoFullscreenPlayerWillDismiss: this._onFullscreenPlayerWillDismiss,
@@ -180,6 +199,8 @@ export default class Video extends Component {
      onPlaybackStalled: this._onPlaybackStalled,
      onPlaybackResume: this._onPlaybackResume,
      onPlaybackRateChange: this._onPlaybackRateChange,
      onAudioFocusChanged: this._onAudioFocusChanged,
      onAudioBecomingNoisy: this._onAudioBecomingNoisy,
    });

    if (this.props.poster && this.state.showPoster) {
@@ -222,6 +243,7 @@ Video.propTypes = {
  fullscreen: PropTypes.bool,
  onVideoLoadStart: PropTypes.func,
  onVideoLoad: PropTypes.func,
  onVideoBuffer: PropTypes.func,
  onVideoError: PropTypes.func,
  onVideoProgress: PropTypes.func,
  onVideoSeek: PropTypes.func,
@@ -248,11 +270,13 @@ Video.propTypes = {
  rate: PropTypes.number,
  playInBackground: PropTypes.bool,
  playWhenInactive: PropTypes.bool,
  disableFocus: PropTypes.bool,
  controls: PropTypes.bool,
  currentTime: PropTypes.number,
  progressUpdateInterval: PropTypes.number,
  onLoadStart: PropTypes.func,
  onLoad: PropTypes.func,
  onBuffer: PropTypes.func,
  onError: PropTypes.func,
  onProgress: PropTypes.func,
  onSeek: PropTypes.func,
@@ -265,6 +289,8 @@ Video.propTypes = {
  onPlaybackStalled: PropTypes.func,
  onPlaybackResume: PropTypes.func,
  onPlaybackRateChange: PropTypes.func,
  onAudioFocusChanged: PropTypes.func,
  onAudioBecomingNoisy: PropTypes.func,

  /* Required by react-native */
  scaleX: PropTypes.number,
+47 −0
Changes for android-exoplayer/README.md: 47 added lines, 0 removed lines.
Original line number Diff line number Diff line
## react-native-video - ExoPlayer

This is an Android React Native video component based on ExoPlayer v2.

> ExoPlayer is an application level media player for Android. It provides an alternative to Android’s MediaPlayer API for playing audio and video both locally and over the Internet. ExoPlayer supports features not currently supported by Android’s MediaPlayer API, including DASH and SmoothStreaming adaptive playbacks. Unlike the MediaPlayer API, ExoPlayer is easy to customize and extend, and can be updated through Play Store application updates.

https://github.com/google/ExoPlayer

## Benefits over `react-native-video@0.9.0`:

- Android Video library built by Google, with a lot of support
- Supports DASH, HlS, & SmoothStreaming adaptive streams
- Supports formats such as MP4, M4A, FMP4, WebM, MKV, MP3, Ogg, WAV, MPEG-TS, MPEG-PS, FLV and ADTS (AAC).
- Fewer device specific issues
- Highly customisable

## ExoPlayer only props

```javascript

  render() {
    return (
      <Video
        ...
        disableFocus={true} // disables audio focus and wake lock (default false)
        onAudioBecomingNoisy={this.onAudioBecomingNoisy} // Callback when audio is becoming noisy - should pause video
        onAudioFocusChanged={this.onAudioFocusChanged} // Callback when audio focus has been lost - pause if focus has been lost
      />
    )
  }

  onAudioBecomingNoisy = () => {
    this.setState({ pause: true })
  }

  onAudioFocusChanged(event: { hasAudioFocus: boolean }) {
    if (!this.state.paused && !event.hasAudioFocus) {
      this.setState({ paused: true })
    }
  }
```

## Unimplemented props

- `playInBackground={true}`
- `rate={1.0}`
- Expansion file - `source={{ mainVer: 1, patchVer: 0 }}`
+20 −0
Changes for android-exoplayer/build.gradle: 20 added lines, 0 removed lines.
Original line number Diff line number Diff line
apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 23
    }
}

dependencies {
    provided 'com.facebook.react:react-native:+'
    compile 'com.google.android.exoplayer:exoplayer:r2.1.1'
    compile('com.google.android.exoplayer:extension-okhttp:r2.1.1') {
        exclude group: 'com.squareup.okhttp3', module: 'okhttp'
    }
    compile 'com.squareup.okhttp3:okhttp:3.4.2'
}
+3 −0
Changes for android-exoplayer/src/main/AndroidManifest.xml: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.brentvatne.react">
</manifest>
Loading