3

I'm trying to play a video in my React-Native application but I just want to use the standard video player that is built into the operating systems. Such as when you are in Safari or Chrome on your phone then you press the play button on a video. I essentially want that in my app but everything I see is telling me use the library called react-native-video, which from what I can see requires you to completely make your own video player.

Frankly I need something that just takes a url as the source and onPress it opens the native video player built into the operating system. Does anyone know if this is possible?

Ryan Wilson
  • 1,743
  • 3
  • 15
  • 26
  • After some digging through documentation and issues I've found that using the `react-native-video` library has a method called `presentFullscreenPlayer` which does what I need, at least for iOS. Currently Android does not seem to be working with this method. So if you only need this for iOS you should be fine just using the library but if you need this for Android (like I do) this will not currently work. Here is the issue in github: https://github.com/react-native-community/react-native-video/issues/726. This also has an example of how to use `presentFullscreenPlayer` – Ryan Wilson Aug 07 '17 at 22:45
  • Ok, But is there any API that we can call for open built in Video players – Pravin Aug 03 '18 at 10:29

2 Answers2

0

You're looking for Linking (usage explanation) specifically with use with Android Intents. Depending on what your url looks like (http, local filesystem), this should work or you may need a different module.

Simple example of opening http url of a video:

Linking.openURL('http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4')

On my Android device, this will by default open up the list where it gives me the option to open the url in different applications (in my case, I chose MX Player and it played the video fine).

I haven't been able to track down the documentation for the various supported Android schemes (for example, to open it with MX Player by default), but it should be possible. If not, then you can look at the answers to similar questions with 3rd party module solutions:

If you happen upon finding the specific uri scheme for Linking to open videos in specific players, do comment and I'll edit it into the answer since I'm sure it'll help others.

Michael Cheng
  • 9,644
  • 6
  • 46
  • 48
  • Thanks for the quick response, but I'm actually looking for something that feels more native to the app. While linking does seem to work it forces me to leave the app to enter my browser to play the video. I need some way of playing the video in the native player without leaving the app. – Ryan Wilson Aug 07 '17 at 22:40
  • @RyanWilson Ah ok, misunderstood what you were looking for since it sounded like `react-native-video` wasn't the behavior you were looking for. Seeing your new comment shows that this wasn't the case. You should probably edit your question to include your comment since it makes it more clear what you're looking for. – Michael Cheng Aug 07 '17 at 23:50
  • I want the same – Pravin Aug 03 '18 at 10:13
0

In React Native to play video in an external video player:

 import {NativeModules} from 'react-native';  //import Native Modules

 const Video = () => {
   const SendIntentAndroid = NativeModules?.SendIntentAndroid || {};

 // call this function to play your video in an external video player
  const onVideoPlay = path => {
   SendIntentAndroid?.openAppWithData(
    null, // Package name
    path, // uri
    'video/*', // mime/type
    {},
   );
  };


 return (
        <Button title="Play Video" onPress={onVideoPlay}  />
      )
   }
Muhammad Haidar
  • 1,541
  • 16
  • 17