question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Video pausing and possibly unmounting when navigating away from screen using react navigation (but not pausing on iOS)

See original GitHub issue

Bug

On android when I navigate to another screen (using stack navigator or bottom tab navigator. Version : react-navigation : “4.4.2”, “react-navigation-stack”: “2.8.4”, “react-navigation-tabs”: “2.9.2”, ) the video is paused, or even unmounted because when i get back to the video it starts again from the beginning of the media (can’t resume the video except with the seek method). But on iOS, when I navigate away to another screen (with no video), the video is still playing in the background.

This is the behavior I would like (on iOS) as I want to resume video when going back to the video screens (I handle pause/play with on focus/blur events in react navigation).

Is there anyway to have the same behavior on android ?

Platform

Which player are you experiencing the problem on:

  • Android ExoPlayer

Environment info

React native info output:

System:
    OS: Windows 10 10.0.19042
    CPU: (12) x64 AMD Ryzen 5 3600 6-Core Processor
    Memory: 3.50 GB / 15.95 GB
  Binaries:
    Node: 14.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 6.14.11 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK: Not Found
  IDEs:
    Android Studio: Version  4.1.0.0 AI-201.8743.12.41.7199119
    Visual Studio: Not Found
  Languages:
    Java: Not Found
    Python: 3.9.2
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1
    react-native: ~0.63.3 => 0.63.4
    react-native-windows: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Library version: 5.1.1

Steps To Reproduce

Expected behaviour

  1. I want the video to keep playing when navigating away from the screen (like on iOS)

Reproducible sample code

link to reproductible demo : https://github.com/qhoarau/ReactNativeVideoBugDemo

Video sample

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

4reactions
qhoaraucommented, Aug 12, 2021

Hey I too faced the same problem actually in my case i was using nested stack navigator inside bottom navigation I dont know the reason tho , but figured it out it was due to that only, so I moved my audio component in the screen which was actually the root child for the bottom navigator as my player was initially in the nested stack.

Bug

On android when I navigate to another screen (using stack navigator or bottom tab navigator. Version : react-navigation : “4.4.2”, “react-navigation-stack”: “2.8.4”, “react-navigation-tabs”: “2.9.2”, ) the video is paused, or even unmounted because when i get back to the video it starts again from the beginning of the media (can’t resume the video except with the seek method). But on iOS, when I navigate away to another screen (with no video), the video is still playing in the background. This is the behavior I would like (on iOS) as I want to resume video when going back to the video screens (I handle pause/play with on focus/blur events in react navigation). Is there anyway to have the same behavior on android ?

Platform

Which player are you experiencing the problem on:

  • Android ExoPlayer

Environment info

React native info output:

System:
    OS: Windows 10 10.0.19042
    CPU: (12) x64 AMD Ryzen 5 3600 6-Core Processor
    Memory: 3.50 GB / 15.95 GB
  Binaries:
    Node: 14.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 6.14.11 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK: Not Found
  IDEs:
    Android Studio: Version  4.1.0.0 AI-201.8743.12.41.7199119
    Visual Studio: Not Found
  Languages:
    Java: Not Found
    Python: 3.9.2
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1
    react-native: ~0.63.3 => 0.63.4
    react-native-windows: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Library version: 5.1.1

Steps To Reproduce

Expected behaviour

  1. I want the video to keep playing when navigating away from the screen (like on iOS)

Reproducible sample code

Video sample

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

Thanks for your answer, I tried it but even with my video component as the root child of the bottom tab bar it still behaves the same way.

I made a reproductible demo code available here : https://github.com/qhoarau/ReactNativeVideoBugDemo

Running this on android : when navigating to another screen, the video stops

Running this on iOS : when navigating to another screen, the video keeps playing (that’s what I want)

I don’t really know what to do

3reactions
hirbodcommented, Jul 13, 2022

The main reason is react-native-reanimated. If you’re using “LayoutAnimation” (it does not matter where inside the app, a single usage is enough to enable internal snapshotting) - will break unmounting of elements.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-native-video : Video stops when navigating away to ...
On android when I navigate to another screen (using stack navigator or bottom tab navigator ) the video (using react-native-video) is paused ......
Read more >
Reactnativevideo: Video Stops When Navigating Away To
Video pausing and possibly unmounting when navigating away from screen using react navigation but not pausing on iOS #2448. React rtmp player.js is...
Read more >
How to pause a video when navigating to another screen ...
I had to play a video on a screen whose application used a Bottom Tab ... screen using Tab and Stack Navigator in...
Read more >
Handling Mounting And Unmounting Of Navigation Routes In ...
Let's look at how to mount and unmount navigation stack based on a met condition in React Native. In this article, we are...
Read more >
React v18.0 – React Blog
React may start rendering an update, pause in the middle, ... fetching with Suspense is technically possible, but still not recommended as a ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found