Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.8.0

* Adds platform view support for macOS.

## 2.7.3

* Restructures the communication between Dart and native code.
Expand Down
4 changes: 0 additions & 4 deletions packages/video_player/video_player_avfoundation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,3 @@ should add it to your `pubspec.yaml` as usual.

[1]: https://pub.dev/packages/video_player
[2]: https://flutter.dev/to/endorsed-federated-plugin

## Platform limitations

On macOS, the plugin does not currently support platform views. Instead, a texture view is always used to display the video player, even if `VideoViewType.platformView` is specified as a parameter.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@

#import <OCMock/OCMock.h>
#import <video_player_avfoundation/AVAssetTrackUtils.h>
#import <video_player_avfoundation/FVPNativeVideoViewFactory.h>
#import <video_player_avfoundation/FVPTextureBasedVideoPlayer_Test.h>
#import <video_player_avfoundation/FVPVideoPlayerPlugin_Test.h>

#if TARGET_OS_IOS
#import <video_player_avfoundation/FVPNativeVideoViewFactory.h>
#endif

#if TARGET_OS_IOS
@interface FakeAVAssetTrack : AVAssetTrack
@property(readonly, nonatomic) CGAffineTransform preferredTransform;
Expand Down Expand Up @@ -801,7 +798,6 @@ - (void)testHotReloadDoesNotCrash {
handler:nil]; // No assertions needed. Lack of crash is a success.
}

#if TARGET_OS_IOS
- (void)testNativeVideoViewFactoryRegistration {
NSObject<FlutterPluginRegistrar> *registrar = OCMProtocolMock(@protocol(FlutterPluginRegistrar));

Expand All @@ -811,7 +807,6 @@ - (void)testNativeVideoViewFactoryRegistration {

OCMVerifyAll(registrar);
}
#endif

- (void)testPublishesInRegistration {
NSObject<FlutterPluginRegistrar> *registrar = OCMProtocolMock(@protocol(FlutterPluginRegistrar));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@ - (instancetype)initWithMessenger:(NSObject<FlutterBinaryMessenger> *)messenger
return self;
}

#pragma mark - FlutterPlatformViewFactory

#if TARGET_OS_OSX
- (NSView *)createWithViewIdentifier:(int64_t)viewIdentifier
arguments:(FVPPlatformVideoViewCreationParams *)args {
#else
- (NSObject<FlutterPlatformView> *)createWithFrame:(CGRect)frame
viewIdentifier:(int64_t)viewIdentifier
arguments:(FVPPlatformVideoViewCreationParams *)args {
#endif
NSNumber *playerIdentifier = @(args.playerId);
FVPVideoPlayer *player = self.playerByIdProvider(playerIdentifier);
return [[FVPNativeVideoView alloc] initWithPlayer:player.player];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@
#import "./include/video_player_avfoundation/FVPAVFactory.h"
#import "./include/video_player_avfoundation/FVPDisplayLink.h"
#import "./include/video_player_avfoundation/FVPFrameUpdater.h"
#import "./include/video_player_avfoundation/FVPNativeVideoViewFactory.h"
#import "./include/video_player_avfoundation/FVPTextureBasedVideoPlayer.h"
#import "./include/video_player_avfoundation/FVPVideoPlayer.h"
// Relative path is needed for messages.g.h. See
// https://github.com/flutter/packages/pull/6675/#discussion_r1591210702
#import "./include/video_player_avfoundation/messages.g.h"

#if TARGET_OS_IOS
// Platform views are only supported on iOS as of now.
#import "./include/video_player_avfoundation/FVPNativeVideoViewFactory.h"
#endif

#if !__has_feature(objc_arc)
#error Code Requires ARC.
#endif
Expand Down Expand Up @@ -61,15 +57,12 @@ @implementation FVPVideoPlayerPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
FVPVideoPlayerPlugin *instance = [[FVPVideoPlayerPlugin alloc] initWithRegistrar:registrar];
[registrar publish:instance];
#if TARGET_OS_IOS
// Platform views are only supported on iOS as of now.
FVPNativeVideoViewFactory *factory = [[FVPNativeVideoViewFactory alloc]
initWithMessenger:registrar.messenger
playerByIdentifierProvider:^FVPVideoPlayer *(NSNumber *playerIdentifier) {
return instance->_playersByIdentifier[playerIdentifier];
}];
[registrar registerViewFactory:factory withId:@"plugins.flutter.dev/video_player_ios"];
#endif
SetUpFVPAVFoundationVideoPlayerApi(registrar.messenger, instance);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Platform views are only supported on iOS as of now. Ifdefs are used to avoid compilation errors.

#import <AVFoundation/AVFoundation.h>

#if TARGET_OS_OSX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Platform views are only supported on iOS as of now. Ifdef is used to avoid compilation errors.

#import <Foundation/Foundation.h>

#import "FVPVideoPlayer.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "../video_player_avfoundation/include/video_player_avfoundation/FVPNativeVideoView.h"

#import <AVFoundation/AVFoundation.h>
#import <QuartzCore/QuartzCore.h>

@implementation FVPNativeVideoView

- (instancetype)initWithPlayer:(AVPlayer *)player {
self = [super init];
if (self) {
self.wantsLayer = YES;
((AVPlayerLayer *)self.layer).player = player;
}
return self;
}

- (CALayer *)makeBackingLayer {
return [[AVPlayerLayer alloc] init];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

// ignore_for_file: public_member_api_docs

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:video_player_platform_interface/video_player_platform_interface.dart';

Expand Down Expand Up @@ -44,27 +42,20 @@ class _App extends StatelessWidget {
),
),
body: TabBarView(
children: Platform.isIOS
? <Widget>[
_ViewTypeTabBar(
builder: (VideoViewType viewType) =>
_BumbleBeeRemoteVideo(viewType),
),
_ViewTypeTabBar(
builder: (VideoViewType viewType) =>
_BumbleBeeEncryptedLiveStream(viewType),
),
_ViewTypeTabBar(
builder: (VideoViewType viewType) =>
_ButterFlyAssetVideo(viewType),
),
]
// Platform views are only supported on iOS as of now.
: const <Widget>[
_BumbleBeeRemoteVideo(VideoViewType.textureView),
_BumbleBeeEncryptedLiveStream(VideoViewType.textureView),
_ButterFlyAssetVideo(VideoViewType.textureView),
],
children: <Widget>[
_ViewTypeTabBar(
builder: (VideoViewType viewType) =>
_BumbleBeeRemoteVideo(viewType),
),
_ViewTypeTabBar(
builder: (VideoViewType viewType) =>
_BumbleBeeEncryptedLiveStream(viewType),
),
_ViewTypeTabBar(
builder: (VideoViewType viewType) =>
_ButterFlyAssetVideo(viewType),
),
],
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:video_player_platform_interface/video_player_platform_interface.dart';
Expand Down Expand Up @@ -73,10 +72,7 @@ class AVFoundationVideoPlayer extends VideoPlayerPlatform {
@override
Future<int?> createWithOptions(VideoCreationOptions options) async {
final DataSource dataSource = options.dataSource;
// Platform views are not supported on macOS yet. Use texture view instead.
final VideoViewType viewType = defaultTargetPlatform == TargetPlatform.macOS
? VideoViewType.textureView
: options.viewType;
final VideoViewType viewType = options.viewType;

String? asset;
String? packageName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: video_player_avfoundation
description: iOS and macOS implementation of the video_player plugin.
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_avfoundation
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
version: 2.7.3
version: 2.8.0

environment:
sdk: ^3.6.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
Expand Down Expand Up @@ -293,8 +292,7 @@ void main() {
const VideoPlayerTextureViewState(textureId: newPlayerId));
});

test('createWithOptions with platform view on iOS', () async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
test('createWithOptions with platform view', () async {
final (
AVFoundationVideoPlayer player,
MockAVFoundationVideoPlayerApi api,
Expand Down Expand Up @@ -322,36 +320,6 @@ void main() {
const VideoPlayerPlatformViewState());
});

test('createWithOptions with platform view uses texture view on MacOS',
() async {
debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
final (
AVFoundationVideoPlayer player,
MockAVFoundationVideoPlayerApi api,
_,
) = setUpMockPlayer(playerId: 1);
const int newPlayerId = 2;
when(api.create(any)).thenAnswer((_) async => newPlayerId);

final int? playerId = await player.createWithOptions(
VideoCreationOptions(
dataSource: DataSource(
sourceType: DataSourceType.file,
uri: 'file:///foo/bar',
),
viewType: VideoViewType.platformView,
),
);

final VerificationResult verification = verify(api.create(captureAny));
final CreationOptions creationOptions =
verification.captured[0] as CreationOptions;
expect(creationOptions.viewType, PlatformVideoViewType.textureView);
expect(playerId, newPlayerId);
expect(player.playerViewStates[newPlayerId],
const VideoPlayerTextureViewState(textureId: newPlayerId));
});

test('setLooping', () async {
final (
AVFoundationVideoPlayer player,
Expand Down