Skip to content

Instantly share code, notes, and snippets.

@irvin373
Created June 27, 2020 23:16
Show Gist options
  • Save irvin373/a771fc955df6d59b7c2a69858715c80a to your computer and use it in GitHub Desktop.
Save irvin373/a771fc955df6d59b7c2a69858715c80a to your computer and use it in GitHub Desktop.
package com.fullscreenvideoandroid;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.provider.MediaStore;
import com.facebook.react.bridge.ActivityEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
public class VideoPlayerModule extends ReactContextBaseJavaModule implements ActivityEventListener {
public final int VIDEO_CODE = 1;
public VideoPlayerModule(ReactApplicationContext reactContext) {
super(reactContext);
}
@Override
public String getName() {
return "VideoPlayerManager";
}
@ReactMethod
public void showVideoPlayer(String url) {
Activity currentActivity = getCurrentActivity();
if (currentActivity != null) {
Intent videoIntent = new Intent(Intent.ACTION_VIEW);
videoIntent.setDataAndType(Uri.parse(url), "video/*");
currentActivity.startActivityForResult(videoIntent, VIDEO_CODE);
}
}
@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
if (requestCode == VIDEO_CODE) {
getCurrentActivity().finish();
}
}
@Override
public void onNewIntent(Intent intent) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment