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

[DRAFT] video_player platform view support #1

Draft
wants to merge 97 commits into
base: main
Choose a base branch
from

Conversation

FirentisTFW
Copy link

@FirentisTFW FirentisTFW commented Nov 18, 2024

This PR adds support for platform views on iOS as a way of displaying a video. When creating a video, it's now possible to choose between texture view approach (rendered using Texture widget on the Flutter side) and platform view approach (rendered on the native side, using AVPlayerLayer).

FVPVideoPlayer class now has nothing to do with texture. The texture-related code was moved from it to FVPVideoPlayerTextureApproach - a subclass of FVPVideoPlayer that adds texture functionality. In the plugin class (createWithOptions method) we create either the basic version (for platform view) or the texture subclass (in case of texture approach) based on the parameter passed in from Flutter side.

Platform view is only supported on iOS, no MacOS implementation is added in this PR. The functionality is not yet exposed in the app-facing package (only in example app) - it will be done later, once we add the Android implementation. The PR does not introduce breaking changes, I followed the rule "non-breaking changes, even at the expense of a less-clean API" (buildViewWithOptions method, viewType in DataSource).

Up to this point, the variable naming relied heavily on the texture (we had a lot of textureId variables and properties). Since now you can use a platform view instead of a texture view, these variables and parameters will be renamed to just playerId. This will be done in a separate PR to keep git diff for this one clean.

I left some comments in the PR to clarify/discuss some choices.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@@ -0,0 +1,20 @@
#import "FVPFrameUpdater.h"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whole file content extracted from FVPVideoPlayerPlugin.m

@@ -0,0 +1,164 @@
#import "FVPVideoPlayerTextureApproach.h"

@implementation FVPVideoPlayerTextureApproach
Copy link
Author

@FirentisTFW FirentisTFW Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was a part of FVPVideoPlayer class. It is all related to texture approach. I extracted it from FVPVideoPlayer and put here. This class extends FVPVideoPlayer and adds texture approach specific code.

@FirentisTFW FirentisTFW force-pushed the feature/video-player-platform-view-support branch from 4059fbf to 15618d5 Compare November 19, 2024 12:40
Comment on lines 31 to 58
- (instancetype)initWithURL:(NSURL *)url
httpHeaders:(nonnull NSDictionary<NSString *, NSString *> *)headers
avFactory:(id<FVPAVFactory>)avFactory
registrar:(NSObject<FlutterPluginRegistrar> *)registrar;

- (instancetype)initWithPlayerItem:(AVPlayerItem *)item
avFactory:(id<FVPAVFactory>)avFactory
registrar:(NSObject<FlutterPluginRegistrar> *)registrar;

- (instancetype)initWithAsset:(AVPlayerItem *)item
avFactory:(id<FVPAVFactory>)avFactory
registrar:(NSObject<FlutterPluginRegistrar> *)registrar;

- (void)updatePlayingState;

- (void)dispose;

- (void)disposeSansEventChannel;

- (void)setVolume:(double)volume;

- (void)setPlaybackSpeed:(double)speed;

- (void)play;

- (void)pause;

- (void)seekTo:(int64_t)location completionHandler:(void (^)(BOOL))completionHandler;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add many of these methods to the interface because they were referenced in FVPVideoPlayerPlugin.m (and now the player is not longer a part of that file)

@FirentisTFW FirentisTFW self-assigned this Nov 19, 2024
@FirentisTFW FirentisTFW force-pushed the feature/video-player-platform-view-support branch 2 times, most recently from a0ac882 to 3ff70e8 Compare November 20, 2024 16:10
@FirentisTFW FirentisTFW force-pushed the feature/video-player-platform-view-support branch from 223fedc to 282e746 Compare November 26, 2024 12:05
@FirentisTFW FirentisTFW changed the base branch from main to feature/video-player-ios-split-native-code-into-files November 26, 2024 12:08
@FirentisTFW FirentisTFW force-pushed the feature/video-player-platform-view-support branch from eae938d to 60a1733 Compare November 26, 2024 14:50
@FirentisTFW FirentisTFW force-pushed the feature/video-player-platform-view-support branch from 455eec0 to b19ca86 Compare December 5, 2024 15:25
@FirentisTFW FirentisTFW force-pushed the feature/video-player-platform-view-support branch from 2caee49 to f04ed06 Compare December 5, 2024 16:29
@FirentisTFW FirentisTFW force-pushed the feature/video-player-platform-view-support branch from 0dd88a2 to c2117a8 Compare December 6, 2024 10:04
@FirentisTFW FirentisTFW force-pushed the feature/video-player-platform-view-support branch from 7a727b9 to 0184df3 Compare December 6, 2024 13:00
@FirentisTFW FirentisTFW force-pushed the feature/video-player-platform-view-support branch from 0184df3 to 5f31fc3 Compare December 6, 2024 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant