TheWidlarzGroup / react-native-video

A <Video /> component for react-native
https://docs.thewidlarzgroup.com/react-native-video/
MIT License
7.2k stars 2.9k forks source link

[Android] Getting the video dimensions #203

Closed bcalik closed 8 years ago

bcalik commented 8 years ago

Is it possible to get actual video dimensions (width and height)?

I am trying to make a video cropper UI. So I need the actual dimensions of video, then wrap it to a View with overflow hidden, then move the video inside using PanResponder.

Thank you.

sjchmiela commented 8 years ago

The dimensions are posted in onLoad event body.

bcalik commented 8 years ago

@sjchmiela Thanks! I did not notice that. It should be documented in readme.

bcalik commented 8 years ago

@sjchmiela Ok I couldn't get it :/

That's all I get:

canPlayFastForward: true
canPlayReverse: true
canPlaySlowForward: true
canPlaySlowReverse: true
canStepBackward: true
canStepForward: true
currentTime: 0
duration: 15
target: 870
sjchmiela commented 8 years ago

You're right, the changes and callbacks haven't been published to the npm yet. You've got to either point your package.json dependency to eg. master branch of this repo, or to wait for the new version to be pushed to npm, or to fork this repo and point the dependency to it.

bcalik commented 8 years ago

Here is my package.json content:

"react-native-video": "git://github.com/brentvatne/react-native-video#master",

I see the following code in my node_modules/react-native-video/RCTVideo.m file on line 287:

@"naturalSize": @{
  @"width": width,
  @"height": height
},

I restarted the packager, and reloaded the app. But interestingly I still don't get the result back.

@sjchmiela Do you have any idea?

Edit: Ok I finally get it working, I forget to recompile. Thank you very much.

@sjchmiela Will this be implemented for Android in soon? 🙏

bcalik commented 8 years ago

Dimensions return wrong values if the video is in landscape orientation. Please check this pull request, I appended the orientation information: https://github.com/brentvatne/react-native-video/pull/205

sjchmiela commented 8 years ago

I don't develop on Android, sorry… 😞

I'll leave it open until Android side is implemented.

bcalik commented 8 years ago

I don't develop too. But it is as simple as this:

mp.getVideoWidth();
mp.getVideoHeight();

Should be used right here: https://github.com/brentvatne/react-native-video/blob/master/android/src/main/java/com/brentvatne/react/ReactVideoView.java#L225

I will try that and make a pull request some day in next weeks.

bcalik commented 8 years ago

Android version is ready. PR https://github.com/brentvatne/react-native-video/pull/239