Show Timer while playing video using react-native-video - react-native

I have a requirement in my project to show timer when the video is playing. I know there are libraries available for this in React Native, but my requirement is to show the Timer below the video player. As the video progresses the time should decrease till the video gets finish. Please help me.
Thanks in advance :)

Finally, I solved it by myself.
I just used the following approach:
<Video
resizeMode={'contain'}
style={{ height: 312 }}
url={url}
placeholder={"https://baconmockup.com/300/200/"}
onProgress={e => this.progress(e)}
ref={(ref) => { this.video = ref }}
/>
progress(e) {
console.warn('Time' + parseInt(e.currentTime))
}
I am using react-native-af-video-player and onProgress solved my purpose which is provided by react-native-video.

Related

Video in full Screen not working in Android react-native-video

<Video
source={{ uri: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" }}
resizeMode="cover"
repeat
controls
fullscreen = {this.state.fullscreen}
fullscreenOrientation = {"landscape"}
//onBuffer={this.onBuffer} // Callback when remote video is buffering
//onError={this.videoError} // Callback when video cannot be loaded
style={styles.backgroundVideo}
/>
I am using this above code and in the Android manifest orientation in portrait. I am click on the full screen state has been changes according to it. But it just exit in a second. As i am getting a little fluctuation and maybe the app is showing full screen and then exit from full screen. But i am not able to see it. Or you can say full screen is not working. As in the IOS it is working properly. I tried multiple from github but not able to achieve it.

How to display a thumbnail of a local video

Do you know a lib / a way to display a thumbnail of a local video ?
I select a video from my device with react-native-image-picker and i would like to display a thumbnail of this video in a View or flatlist in case of several selections
You can use below plugin for get thubmnail form local path
https://github.com/phuochau/react-native-thumbnail#readme
import RNThumbnail from 'react-native-thumbnail';
let getFilePath = ''
RNThumbnail.get(filepath).then((result) => {
console.log(result.path); // thumbnail path
getFilePath = result.path;
})
After getting path for display purpose you can use react-native-video for play and display
react-native-video and use below code
<Video source={{ uri: getFilePath }} pause={true} />
Hope this will work for you.
If you are using Expo and you are not deploying to web, this package will do the job for you: https://docs.expo.dev/versions/latest/sdk/video-thumbnails/

Picache gif is a still image (Expo + ReactNative)

I'm trying to speed up loading a bunch of gifs, but a big limitation is that I'm using Expo, and don't want to detach. I found Picache, which states it can be used just like react native Image. When the page loads though, everything loads super fast now, but the gifs are still and not 'gify'.
<Picache
source={{uri: someURL.gif)}}
style={{height: 300, width: 300, borderRadius: 10}}
/>
I've spent so long trynig to figure out how to speed up loading a bunch of images without detaching. Is there a way to make Picache work with gifs, or a similar easy way to implement?
**Before someone suggests, I've already tried... react-native-fast-image-expo but unfortunately it requires detaching as well. That is the desired package though.
If you don't want to bring out the project, you can replace it with this.
Until Expo added the module,
example:
import {Image} from "react-native-expo-image-cache";
// preview can be a local image or a data uri
const preview = { uri: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==" };
const uri = "https://firebasestorage.googleapis.com/v0/b/react-native-e.appspot.com/o/b47b03a1e22e3f1fd884b5252de1e64a06a14126.png?alt=media&token=d636c423-3d94-440f-90c1-57c4de921641";
<Image style={{ height: 100, width: 100 }} {...{preview, uri}} />
Get the local image from a remote URI
import {CacheManager} from "react-native-expo-image-cache";
const {uri} = this.props;
const path = await CacheManager.get(uri).getPath();
// if path is undefined, the image download has failed

React-native WebView WebKitErrorDomain Error Code: 204

I'm trying to use WebView to display a video hosted on reddit. The link i am using is https://v.redd.it/e3u0b3ej71k11/DASH_2_4_M which is for this post https://v.redd.it/e3u0b3ej71k11/ . On IOS the video will automatically go full screen and play but gives me this error
On android it doesn't give me an error but it has a video that is just black, but does have the correct run time. I'm not really sure how the endpoint DASH_2_4_M works but I got that url from reddit api.
<WebView
source={{uri: this.state.data[0].data.children[0].data.media.reddit_video.fallback_url}}
style={{height: 650, width: '100%'}}
bounces={false}
scrollEnable={false}
/>

React Native Webview get html

I want to get html in web view.
I read react-native-doc(https://facebook.github.io/react-native/docs/webview.html#content) but I cannot found it.
Can I do this?
None of the answers above worked for me, but this did. It displays the received html content of the webview in the console:
const jsCode = 'window.ReactNativeWebView.postMessage(document.documentElement.innerHTML)'
return (
<WebView
injectedJavaScript={jsCode}
source={{ uri: 'https://www.whatever.com' }}
onMessage={event => console.log('Received: ', event.nativeEvent.data)}
javaScriptEnabled
/>
)
I found this.
https://github.com/alinz/react-native-webview-bridge
But I could not use this in android. This works only in android.
I don't know this problem is only my problem or library problem.
In Android I use onNavigationStateChange.
Read https://github.com/facebook/react-native/issues/586#issuecomment-90826117
I think this is not good way. But I really need this. so I used this.
In case anyone comes across this in the future. You options here is to use javascript. You can use injectedJavaScript on the webview to inject a window.postmessge($('body').html()) and then handle the reply in the onMessage function on the webview. The cleaner way would be to fetch the page yourself and then load it into the webview.