Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to obtain video proportion #42

Open
chengyeah opened this issue Jan 24, 2025 · 2 comments
Open

How to obtain video proportion #42

chengyeah opened this issue Jan 24, 2025 · 2 comments

Comments

@chengyeah
Copy link

chengyeah commented Jan 24, 2025

@override
  Widget build(BuildContext context) {
    return AspectRatio(
      aspectRatio: 16 / 9,
      child: Stack(
        children: [
          Container(
            margin: const EdgeInsets.fromLTRB(0, 40, 0, 40),
            child: NativeVideoPlayerView(
              onViewReady: (controller) async {
                _controller = controller;
                await _controller?.setVolume(1);
                controller.onPlaybackReady.addListener(() {
                  final videoInfo = controller.videoInfo;
                  final videoWidth = videoInfo?.width;
                  final videoHeight = videoInfo?.height;
                  final videoDuration = videoInfo?.duration;
                  final aspectRatio = videoInfo?.aspectRatio;
                  print("videoWidth is: $videoWidth");
                  print("videoHeight is: $videoHeight");
                  print("videoDuration is: $videoDuration");
                  print("aspectRatio is: $aspectRatio");
                });
                controller.onPlaybackStatusChanged.addListener(() {
                  final playbackStatus = controller.playbackInfo?.status;
                  print("playbackStatus is: $playbackStatus");
                });
                controller.onPlaybackPositionChanged.addListener(() {
                  final playbackPosition = controller.playbackInfo?.position;
                  print("playbackPosition is: $playbackPosition");
                });
              },
            ),
          ),
          Material(
            type: MaterialType.transparency,
            child: InkWell(
              onTap: _togglePlayback,
              child: Center(
                child: FutureBuilder(
                  future: _isPlaying,
                  initialData: false,
                  builder: (
                    BuildContext context,
                    AsyncSnapshot<bool> snapshot,
                  ) {
                    final isPlaying = snapshot.data ?? false;
                    return Icon(
                      isPlaying ? Icons.pause : Icons.play_arrow,
                      size: 64,
                      color: Colors.white,
                    );
                  },
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

My example
VideoInfo is not the actual size of the video
How to obtain the actual width and height of a video

🙏🙏🙏

Copy link

Thank you for opening this issue!

I will look into it as soon as possible. In the meantime, please review these important project updates:

Your feedback and contributions are greatly appreciated!

@albemala
Copy link
Owner

albemala commented Feb 3, 2025

@chengyeah could you please test out the latest dev version (https://pub.dev/packages/native_video_player/versions/3.0.0-dev.3) and see if you have the same problem? Thanks! Check out the changelog and readme for the API changes I've made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants