react-native-video: onLoad never gets called, Video Player Stops working completely, App needs to be restarted- Android

Bug

This is a hard one to track and reproduce. onError doesn’t get called when this happens.

I have a flatlist with several items. When the user taps on an item, a video loads in the top section and plays. The video being loaded at the moment is an mp4 coming from an AWS CDN link.

This works as expected on iOS. On Android, sometimes the video will either never load or stop playing during playback. I noticed that the onBuffer method is called with isBuffering: true and never switches back to false. When this issue happens when loading, the onLoadStart method is called but onLoad is never called. My activity indicator keeps on spinning and the video container has a black screen. If I try to load another video, I get the same issue. The url is stored in the reducer during the session, so if I clear the reducer and load it again, the issue still persists. The only way to fix this is by completely closing the app is opening it back up.

I’ve tried using the Android Media Player and still encounter the issue there.

Since this doesn’t throw an error, I have no error message to produce.

Has anybody encountered this problem or know of a fix I could attempt?

Platform

Android Exoplayer Android Media Player

Environment info

React native info output:

System:
    OS: macOS 11.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 1.62 GB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 13.11.0 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.13.7 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.10.0 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.2, DriverKit 20.0, macOS 11.0, tvOS 14.2, watchOS 7.1
    Android SDK:
      API Levels: 28, 29
      Build Tools: 28.0.3, 29.0.2, 30.0.0
      System Images: android-29 | Google APIs Intel x86 Atom, android-30 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 3.6 AI-192.7142.36.36.6241897
    Xcode: 12.2/12B45b - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_222 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1 
    react-native: 0.63.2 => 0.63.2 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Library version: 5.0.2

Steps To Reproduce

  1. Click on List Item
  2. Video should load
  3. 1 out of 10 times it does not load. When it doesn’t, onLoad is not called and buffering is set to true
  4. Restart App
  5. Try again, Video loads this time

…

Expected behaviour

  1. Video should load. 2.There should be an error if the video does not load

Reproducible sample code

const Example = ({ mp4Url }) => {
  const [isBufferingNow, setIsBuffering] = useState(true);
  const [showControls, toggleShowControls] = useState(false);

  const videoRef = createRef<Video>();

  const onLoad = (data) => {
    console.log({ data });
  };

  const onBuffer = ({ isBuffering }) => {
    setIsBuffering(isBuffering);
  };

  return (
    <TouchableWithoutFeedback onPress={() => toggleShowControls(!showControls)}>
      <View>
        {isBufferingNow && (
          <View style={styles.videoLoadingIndicator}>
            <ActivityIndicator size="large" animating={isBufferingNow} />
          </View>
        )}
        {!!mp4Url && (
          <Video
            ref={videoRef}
            playWhenInactive
            playInBackground
            // paused={paused}
            controls={false}
            resizeMode="contain"
            muted={false}
            onLoad={onLoad}
            source={{ uri: mp4Url }}
            onBuffer={onBuffer}
            ignoreSilentSwitch="ignore"
          />
        )}
        {showControls && !!mp4Url && <PlayerControls />}
      </View>
    </TouchableWithoutFeedback>
  );
};

Video sample

If possible, include a link to the video that has the problem that can be streamed or downloaded from.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 24

Most upvoted comments

Just happened to me on IOS

I’m not working on that project anymore, but I was using 5.2.1. If i remember correctly I didn’t have any issues on iOS. In the end I remember solving it using ExoPlayer and changing source URLs to http, that magically solved the loading problems. I was digging into the reason but now I can’t remember anymore

@singhagam1 the default player setting is just for Android, I don’t think there are different players on iOS

This is still reproducible in v6, alpha 5. Only on Android, the onLoad event is not fired.