TheWidlarzGroup / react-native-video

A <Video /> component for react-native
MIT License
7.01k stars 2.83k forks source link

[BUG]: Only iOS - CPU Usage goes beyond 100% in background mode #3720

Open iphonic opened 3 weeks ago

iphonic commented 3 weeks ago

Version

6.0.0-beta.8

What platforms are you having the problem on?

iOS

Architecture

Old architecture

What happened?

As seen in some of the threads people are affected by other library with high CPU usage, but not in my case. I turned off all libraries in the screen but the moment the app goes to background while playing Audio the CPU spikes beyond 100%, interestingly when put false to following props playInBackground={false} playWhenInactive={false}

and send the app to background CPU usage become 0, so it is definitely the player not other libraries. Following is my player code, I am changing currentTrack onEnd manually as I have multiple Tracks to be played for over a period of time continuously, noticeably the scenario on Android device is opposite, on Foreground it has high cpu, and in background very low, while on iOS in foreground the CPU usage are nominal, spike is only in background.

<Video
  audioOnly={true}
  style={{opacity: 0.0}}
  source={currentTrack ? {uri: currentTrack.url} : null}
  onError={e => console.log('Error ', e)}
  ref={ref => {
    this.player = ref;
  }}
  controls={false}
  muted={false}
  allowsExternalPlayback={false}
  disableFocus={true}
  repeat={false}
  onEnd={() => {
    this.onVideoEnd();
  }}
  paused={this.state.paused}
  playInBackground={true}
  playWhenInactive={true}
  debug={{
    enable: true,
    thread: true,
  }}
  progressUpdateInterval={
    this.state.appState === 'background' ? 9999999 : 1000.0
  }
  onPlaybackStateChanged={this.onPlaybackStateChanged}
  ignoreSilentSwitch={'ignore'}
  onProgress={({currentTime, playableDuration, seekableDuration}) => {
   let progress = currentTime / seekableDuration;
    let progressPerPart = 1.0 / tracks.length;
    let partProgress = progress * progressPerPart;
    let actualProgress =
      partProgress + progressPerPart * currentTrackIndex;
    let shortProgress = actualProgress.toFixed(2);
    actualProgress = actualProgress.toFixed(3);

    if (
      actualProgress > 0 &&
      actualProgress > this.state.lastprogress
    ) {
      this.setState({
        progress: parseFloat(actualProgress),
        lastprogress: actualProgress,
      });

    } else {
      this.setState({progress: parseFloat(actualProgress)});
    }

  }}
/>

Reproduction

repository link

Reproduction

Step to reproduce this bug are: Simply put multiple tracks and play them in Audio mode, turn on profiler on Xcode while connecting the physical device, send the app to background mode, cpu will spike up.

freeboub commented 2 weeks ago

I tried to reproduce the issue, but unfortunately, I don't see similar behavior... Did you try on 6.0.0-RC.0 ? Is it possible to have a very basic sample to reproduce the issue please ?